Have you ever wondered how your images are stored on your computer, knowing your computer understands only 1’s and 0's?
Perhaps, now you might have guessed that even images are stored as 1’s and 0's! Yes, you are right, images are stored as 1’s and 0’s but how would images be converted to 1’s and 0's?
Let’s know that together!!
To store an image on a computer, the image is first broken down into tiny elements called PIXELS. The smallest element in a picture or image is called Pixel(in short of Picture Element = Pixel).
Now, you may be thinking how many pixels an image has? It’s very simple, the number of pixels is the product of height and width of an image(In other words, we can say it’s calculated using image resolution).
Ex: If your image resolution is 1020 x 800(width x height), the total number of pixels is 816,000.
Now, for the computer to store the image, each pixel is represented by a binary value. How does the pixel is converted to binary values?
For every pixel, an average color is found and a binary value is assigned. For monochrome(two-color) image, only 1 bit is needed to represent each pixel. 0 for white and 1 for black. For colored images, each pixel is represented by multiple bits, one combination per shade. The number of bits allocated for each pixel color is called color depth or bit depth(in simple words, how many bits represent each pixel). If the color depth of an image is 8-bit, the image contains 256 colors. The most common color depths you see are 8-bit(2⁸ = 256 colors), 16-bit (2¹⁶ = 65,536 colors) and 24-bit(2²⁴ = 16.7 million colors). Larger color depth allows more shades and different colors. You can find the color depth or bit depth of your image from your image properties.
For example, for an image that uses 4 colors(2² = 4), 2 bits(color depth is 2-bit) are needed for each pixel. So, in this case, we can have,
00-white; 01-black; 10-yellow; 11-blue;
Similarly, for a color depth of 3, we have 8 colors and we can have,
000-white; 001-black; 010-yellow; 110-blue;
Following are the examples of an image with its binary code or value,
For interpreting the image, the computer needs to know metadata(data about data or extra piece of information we can say) of the image like Resolution(width & height in pixels) and Color depth(how many bits represent each pixel). You can find metadata of your image from image details.
This is how an image is stored on a computer. Have you ever cared about thinking all this or took it for granted? Let me know your answers.