How do spatial compressors reduce file sizes for graphics?
How e开发者_JAVA百科xactly do spatial compressors reduce file sizes for graphics? Does it have to do with pixels, frames, or metadata?
There are basically two different ways of compressing image data, finding repeated patterns, and throwing away less relevant data.
The simplest form of repeated patters is used in run length encoding (RLE), where it finds pixels next to each other that are the same color. A more sophisticated form is used in GIF images, where it finds pixel groups that occurs more than once in the image.
Throwing away data is used extensively in JPEG compression, where it for example starts by dividing the image into color and brightness information, and reducing the color information for each 2x2 pixel group into the average color for the four pixels, thus throwing away about half of the image information with small visual impact.
Generally speaking, it works the same way as it does for humans.
You look at a picture of a house and say "I see a white house, 3 windows, a door, grass outside and a white picket fence". The details like the number, position and orientation of each blade of grass, the precise texture of the paint on the house etc. don't matter for us.
Similarly, when you compress an image you drop details until you reach the file size you need. At its least, an image can be described by one value, averaging every pixel color in the image. You go up from there.
One common technique that's similar to my house example is creating "words" to describe the larger features of an image that get repeated a lot. That's called run-length encoding (RLE) in a general sense, but it can be a lot more than just specific repeated patterns. You can for example describe with the ID 0 something that's similar to 4 vertical green pixels and paste it all over your picture to designate grass.
The techniques used to compress images are limitless, I suggest pursuing a couple of college courses if you're interested in this, as you need a pretty strong background in calculus and pattern recognition for even the least effective methods.
精彩评论