Bits are just bits—1s and 0s. Without instructions for encoding or abstracting the bits, they have no meaning. Think about this: What would happen if an image encoded in RGB format were read as BGR (blue-green-red) format instead? Assuming that all other aspects are the same, blue and red in the image would be reversed, resulting in some alternate color schemes for the image. Although this is a trivial example, it is important to realize that these standards for encoding give meaning to the sea of bits floating around your computer and the Internet.
![Picture](/uploads/6/9/9/0/69906685/screen-shot-2017-03-08-at-8-36-56-am_orig.png)
Using the 16 symbols of hexadecimal, you can represent all the possible permutations of 4 bits! Note that the symbols A–F are used to extend the numerals representing each digit beyond those of decimal—A is equivalent to 10, and F is equivalent to 15. Hexadecimal serves as an abbreviated form of binary!
Black and White
![Picture](/uploads/6/9/9/0/69906685/screen-shot-2017-03-08-at-8-39-25-am_orig.png)
As previously indicated, computer screens use a combination of red, green, and blue to produce all of the displayable colors. Similarly, in Processing, manipulating colors is merely a matter of specifying the amounts of red, green, and blue an object's color contains.
To illustrate how scaling these color amounts (otherwise known as "channels") works, we shall start with a simpler example—grayscale.
Technically, a black and white image comprises two colors, black and white. These could be represented via 1 bit (e.g., 0 for black, 1 for white). However, in Processing (and life), there is more to the spectrum than black or white. Processing allocates 8 bits for specifying shades of gray. This means that there are 28, or 256, different shades of gray possible.
To illustrate how scaling these color amounts (otherwise known as "channels") works, we shall start with a simpler example—grayscale.
Technically, a black and white image comprises two colors, black and white. These could be represented via 1 bit (e.g., 0 for black, 1 for white). However, in Processing (and life), there is more to the spectrum than black or white. Processing allocates 8 bits for specifying shades of gray. This means that there are 28, or 256, different shades of gray possible.
Digital photos tend to be color-rich, digital diagrams tend to be shape-dependent, and digital drawings rely on a great deal of contrast/brightness. Encoding schemes must account for and suit the factors that impact different image types more heavily than others. "There is more than one way to skin a cat," but sometimes one way is better than another! Consider the following factors that impact how an image is to be used:
- information - What kind of image is it? Is it a photograph, a drawing, black & white?
- size - How big is it?
- use - What is the image used for? Is it used for a fax machine, digital photography, a diagram?
- scalability - Does the image need to be scaled? Does it need to be reduced, enlarged, rotated?
Lossy or Lossless?Advantages and Disadvantages and Ideal for...
JPG
GIF
TIFF
PNG
BMP
Digital photos tend to be color-rich, digital diagrams tend to be shape-dependent, and digital drawings rely on a great deal of contrast/brightness. Encoding schemes must account for and suit the factors that impact different image types more heavily than others. "There is more than one way to skin a cat," but sometimes one way is better than another! Consider the following factors that impact how an image is to be used:
- information - What kind of image is it? Is it a photograph, a drawing, black & white?
- size - How big is it?
- use - What is the image used for? Is it used for a fax machine, digital photography, a diagram?
- scalability - Does the image need to be scaled? Does it need to be reduced, enlarged, rotated?
Abstraction rears its beautiful head once again. Bits mean nothing inherently; their meaning depends upon the instructions to decode them. You could conceivably view ASCII text as a JPG. It would probably be ugly noise – or perhaps exhibit a distinct pattern?
- Try the reverse — open a JPG in Notepad or TextEdit.
- Open a file in 'hexdump' to see its hexadecimal representation (BASE16).
- If you are using a Unix-based operating system (e.g., Linux or Mac OS), try using the command `xxd -b` on a file to see its contents in binary bitstrings of 1s and 0s.
As the image is compressed, there are obvious data/quality losses.
Though these examples are indicative of lossy compression, not all compression is lossy. As mentioned previously, lossless compression involves no data loss. With lossless compression, you can convert back to the original at any time (may be time-intensive, however). For example, FLAC audio loses no quality over CD.
This raises the question:
If lossless compression exists, why would anybody want to use lossy compression?Lossy compression algorithms often result in greater reductions of file size, offer the best compression ratios, and are designed to be "good enough" approximations. A good example might be the use of a thumbnail by a website as a link to a larger image. The compressed thumbnail version reduces the amount of data necessary to load the page, but if users would like to see the original image, they can follow a link to that version.
However, lossy compression can never be "undone," because the lossy compression algorithms remove information that isn't necessary for representation, but can never be reconstructed once lost. In other words, you cannot go from a lossy-compressed image back to the original image.
Though these examples are indicative of lossy compression, not all compression is lossy. As mentioned previously, lossless compression involves no data loss. With lossless compression, you can convert back to the original at any time (may be time-intensive, however). For example, FLAC audio loses no quality over CD.
This raises the question:
If lossless compression exists, why would anybody want to use lossy compression?Lossy compression algorithms often result in greater reductions of file size, offer the best compression ratios, and are designed to be "good enough" approximations. A good example might be the use of a thumbnail by a website as a link to a larger image. The compressed thumbnail version reduces the amount of data necessary to load the page, but if users would like to see the original image, they can follow a link to that version.
However, lossy compression can never be "undone," because the lossy compression algorithms remove information that isn't necessary for representation, but can never be reconstructed once lost. In other words, you cannot go from a lossy-compressed image back to the original image.