As you all know computer run on binary that is true of false, 0 or
1, presence or absence of a current so on so how a system that works on binary
show images to screen the secret is in how it handles graphics itself.
See computer handle graphics by combining 3 different colors
namely Red, Green and blue, different intensity of this create different
brightness of color. In computer each of this colors a byte is allocated and it
resembles the intensity of its value. so there is 1 byte for red 1 byte for
green and 1 byte for blue and all together 256 X 256 X 256 colors since byte
has position of 0-255 in binary all 256 colors this is known as 24-bit color
since each color is represented by 24 bit 8 for red, 8 for green and 8 for
blue.
When you want to display in monitor or other device for example
CRT there is 3 guns that fire electrons associate with 3 colors so when you
pass a color code to CRT it takes the red value and fire red gun to that
intensity and get the green value and fire it in that intensity and get the
blue value and fire in that intensity and combination of this intensity when
hit to monitor screen display the appropriate color
In LCD there are three crystals for pixel that when turn give one
of each color (Red, Green or Blue) So when you pass the color code to LCD it
turns it according to the value of the Red for Red crystal Blue for Blue
Crystals and Green for Green Crystal
In LED there are there are 3 LED for pixel which is for Red, Green
and Blue each can be lit to different intensity. When color code pass to this
monitor it take the red value and lit the red to that intensity, take the green
value and lit it to that intensity and take the blue value and lit is to that
intensity.
So how and image file contain an image. Well images are consisting
of set of pixels each having Red, Green and blue values they are tiny dots of a
color that taken together makes a whole image. Image has width and height which
defines how many pixels are across and how many from top to bottom so image
file consists of two parts a header which consist the width and height of this
image and also compression details if any and data part which consist of actual
data that is the RGB (Red, Green & Blue) values of the pixels which stored
at one after another in 3 bytes
When you say BMP image or bitmap image of color 24 this is the
case, all data are row and not compressed but when it comes to GIF, JPG or PNG
it is little different since the image is compressed. there are many ways to compress
an image but all use same principle it uses a color pallet and use that
information store data in image file
If you have 8-bit pallet you can have 256 positions so all
together will have 256 colors which will be stored in head section of the file.
In data all the colors are approximated to one of these 256 colors and now
since we have only 256 colors in the image we can represent it in 1 byte that
is 8 bit not 3 bytes (24 bits) so the size is reduced 3 times and if you have
color value of 00000010 for data value it means it is the third color (since
00000000 is the first) of the color pallet which will store RGB Values
accordingly so in third position of color table it may have color 11000010
00100000 00100000 mapped to it so get this color and use it whenever you see
00000010 at the data section which is simple. Also there are other compression
algorithms like Huffman which use different methods to create color tables so
altogether the size of the image is reduced greatly
so if you have a picture which consist of 800 X 600 pixels it will require 800
X 600 X 3 bytes of information to store it in raw, but by using color
compression and pallets it can be reduced to 1/3-1/4 of its original size that
is why GIF, JPG and PNG files are reduced in size compared to raw BMP. this
method of compression is known as lossy Compression since some Colors of the
image are replace to a common color so small variation of colors are removed
which in turn degrade the quality of the image.
In compression there are two types lossy and lossless lossy is
applied to images sounds and movies in this some data is approximated or
removed so the size is less this degrade the quality of the image or sound but
you get a compact file. The other one is lossless compression, which compress
the file and can be uncompressed to original state. the programs you use zip,
rar or 7 zip is of example for this.
also there are 1 bit or 2 color which is black and white, 2 bit or four color,3
bit or 8 colors and 4-bit color 8 bit and 16-bit color all use to compress an
image, in 1-bit color, color is represented in one bit in data 1 or 0 in 2-bit
color it is represented in 2 bits in data that is 00 01 10 11 in 4 bit there
are 16 colors and so on. There is also 24 bit color images which consists of
all colors RGB. These images have different way of compression in header
section there are more than width and height. It consist of extra information
like compression method color table if any etc…when you use 24 bit color you
cannot use color tables the images data is compressed by a compression method
like Huffman and the encoding table is added at the header.
in PNG and GIF there are transparency too that is you have an
image and background is transparent or semitransparent for this to happened you
need to add a transparent amount as 4 the byte so image with transparency has
RGBA or RGB alpha which say how trance parent it is. Also some trans parent
images have a transparent color so anything of that color will consider as
transparent, for example if black is set as the transparent color then all
places with black will be shown transparent. So if you have RGBA then you will
have an extra alpha value so now pixel is displayed as 1 for red 1 for green 1
for blue and 1 for alpha or transparency so there is 4 bytes for that not 3
which make these image have more bytes that is why some PNG files size is more
than JPG even the image is the same.
you can zip an image to compress it to send via email but it does not count as
image compression some software use methods like zip to compress whole image so
it can be send via email it is a different story
No comments:
Post a Comment