8 Replies - 1930 Views - Last Post: 27 January 2011 - 08:59 AM

#1 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Smallest possible 10x10 image

Posted 26 January 2011 - 02:04 PM

Hello! I'm trying to figure out what image format would use the least amount of data to store a 10x10 pixel image that will only be using 16 colors. A little testing on my own showed PNG as being a surprisingly good choice (only taking about 130 bytes) where as gifs and jpegs both ended up being pretty bad. Is PNG the best choice you guys know of or is there another, far awesomer choice?

Is This A Good Question/Topic? 0
  • +

Replies To: Smallest possible 10x10 image

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2233
  • View blog
  • Posts: 9,401
  • Joined: 29-May 08

Re: Smallest possible 10x10 image

Posted 26 January 2011 - 02:26 PM

If you are saving small images as a file on disk, the minimum disks would depend on the Format (NTFS 1Kb) or on larger disc (4Kb).

Still it doesn't want format it is, it has to be converted to what the OS natively uses.
On Windows this is general a Bitmap.

If they share the same 16 colour it could be worth developing your own grouped format.

10 x 10 = 100 pixels
100 x 4 bits (16==2^4) = 400 bits
400 bits / 8 = 50 bytes.
Was This Post Helpful? 1
  • +
  • -

#3 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: Smallest possible 10x10 image

Posted 26 January 2011 - 02:27 PM

Well, 16 colour values can fit in 4 bits. So you could store the data raw in 10 * 10 * 0.5 = 50 bytes. That's possibly useful if you wanted to put loads of these into a database, and the 16 colours were specified outside of the file. Compression below that (for instance using run-length encoding) is probably not going to be effective. PNG is generally the way forward.
Was This Post Helpful? 1
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5746
  • View blog
  • Posts: 12,555
  • Joined: 16-October 07

Re: Smallest possible 10x10 image

Posted 26 January 2011 - 02:46 PM

Using any format that's "lossy", like jpeg and png, is probably cheating. ;)

As noted, 50 bytes min. However, two elements are missed. First, I need to actually know it's a 10x10 image, so there's a little header info.

If I want anything other than the same 16 colors for every image, I'll want a palette. That, or each of those values has an RGB type format, meaning 16 or 16 million would take the same storage depending on your color depth; straight RGB forgoes palette.

The 10x10 messes with the formats. Most formats use some form of compression. Such things are overhead that will be trivial for a couple mega pixels, but very noticeable for 100. Also, complexity borks compression. A nice RLE will be amazing for a mostly empty image and possibly larger than no compression on a busy image.

One of the simplest formats I can think of is PBM. No tricks, just the facts.

This post has been edited by baavgai: 26 January 2011 - 02:49 PM

Was This Post Helpful? 1
  • +
  • -

#5 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Smallest possible 10x10 image

Posted 26 January 2011 - 02:47 PM

atraub Fail.

This post has been edited by atraub: 26 January 2011 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

#6 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Smallest possible 10x10 image

Posted 26 January 2011 - 03:09 PM

I hadn't considered writing my own file format. That's an interesting idea. Thanks everyone, I will retire to my bat cave and continue researching this.

Whoops, double post, my bad.

This post has been edited by atraub: 26 January 2011 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2233
  • View blog
  • Posts: 9,401
  • Joined: 29-May 08

Re: Smallest possible 10x10 image

Posted 26 January 2011 - 09:48 PM

Using a format I devised.
Best: 6bytes (All Same Colour)
Worst: 64bytes(Alternating Colours)
Mid: 35bytes (29bytes )
Was This Post Helpful? 0
  • +
  • -

#8 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Smallest possible 10x10 image

Posted 27 January 2011 - 07:31 AM

That's awesome, I think I'm ready for the next Python discussion. Be on the lookout!

This post has been edited by atraub: 27 January 2011 - 08:15 AM

Was This Post Helpful? 0
  • +
  • -

#9 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Smallest possible 10x10 image

Posted 27 January 2011 - 08:59 AM

Alright, here is the newest disucssion. What can I say, this thread inspired me :)

Python Function Challenge 3
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1