How Image Optimization works?

I am wondering because I would like to make my own custom Image Optimizer.

Any and All help appreciated.

Thnx

neksus

Mastermind

Posts: 2193

Loc: Canada

3+ Months Ago

The number of colours are reduced; frequency of colours and gradients are merged. No clue how the programming end of it works though,

joebert

Fart Bubbles

Posts: 13506

Loc: Florida

3+ Months Ago

Think of a 256 color GIF palette.

If you have RGB(255, 255, 255) then in the next pixel you have RGB(255, 255, 254) it's going to save an entry in the palette to snap the latter to 255,255,255.

Basic optimization is looking at the file format you want to save the image to & how many colors it will allow, determining which colors are most popular in the image, building a base palette from that, & snapping colors to this base palette.

Ah I always thought they worked like that, never really looked into it (which is weird, considering I research all the stupid little things).

joebert

Fart Bubbles

Posts: 13506

Loc: Florida

3+ Months Ago

That's a basic raw bitmap view of it.

When you get into formats like PNG, PSD that save layer & vector information it's a whole new ballgame.

Moved to Digital Art/Photography being it's an image specific question.

gaparker

Proficient

Posts: 412

Loc: England, uk

3+ Months Ago

im getting some new animation software that i need to get to grips with, flash, its meant to be really good

ScienceOfSpock

Mastermind

Posts: 1893

Loc: Las Vegas

3+ Months Ago

For lossy formats, like jpeg, the optimization is a bit different. It still uses color similarity to do the optimization, and setting the compreassion/quality level determines the threshold.

For example, if you have large areas of "black" in an image, instead of storing data for every pixel in that area, optimization will break it down into a few "Large pixels". If the optimization has determined that a 25x25 block of pixels are similar enough in color to be considered the same, it will store the color, the size and the location of the block, instead of saving the color information for all 625 pixels.

Obviously, the process is much more complex than that, but that's the easiest way I could think of to explain it.

For reference, here are some size comparisons for a few black field images.

This was done using photoshop 7.01 with the standard "save as..." jpg compression. Note that jpeg format uses this blocking technique for blocks of colors that are exactly the same even at maximum quality, which is why jpeg images are almost always signifigantly smaller than a bitmap of the same image.
I believe jpeg format also employs some form of pattern matching as well. I tested with a 640x480 image of a checkerboard of alternating black and white pixels, and a max quality jpeg was still signifigantly smaller than the bmp version. if it was only using color matching, then I would think that the largest color block it would be able to identify would be a 1x1 pixel, in which case it would have to store a block for each pixel.