Concept of Bits Per Pixel
BPP or Bits per Pixel is used to denote the number of bits per pixel and the number depends on the
depth of color or BPP.
Bits
A bit also known as a binary digit is the smallest unit of data in a computer. A bit has 0 or 1.
Formula:
Following are the number of different colors:
Hello Java Program for Beginners
Bits per pixel Number of colors
1 bpp 2 colors
2 bpp 4 colors
3 bpp 8 colors
4 bpp 16 colors
5 bpp 32 colors
6 bpp 64 colors
7 bpp 128 colors
8 bpp 256 colors
10 bpp 1024 colors
16 bpp 65536 colors
24 bpp 16777216 colors (16.7 million colors)
32 bpp 4294967296 colors (4294 million colors)
Shades
The human eye can distinguish hundreds of color shades and their intensities. There are 100 shades of
grey; therefore, an image contains extra information of color and this information is used for image
analysis.
For example: Identification of object and extraction based on color.
Image storage requirements
Image size
The size of an image depends on three things they are as following :
o Number of rows
o Number of columns
o Number of bits per pixel
The formula for calculating the size of the image:
Example:
Let row be 3000 and columns be 1687, and it has 256 shades of bpp.
Size of an image = rows * cols * bpp
=3000 * 1687 * 8
=40488000 bits
As it is not a standard answer so we can convert it in the following ways:
Converting it into bytes = 8388608 / 8 = 5061000 bytes.
Converting into kilo bytes = 5061000 / 1024 = 4942kb.
Converting into Mega bytes = 4942 / 1024 = 4 Mb.
Types of Images
There are three types of images. They are as following:
1. Binary Images
It is the simplest type of image. It takes only two values i.e, Black and White or 0 and 1. The binary image
consists of a 1-bit image and it takes only 1 binary digit to represent a pixel. Binary images are mostly
used for general shape or outline.
For Example: Optical Character Recognition (OCR).
Binary images are generated using threshold operation. When a pixel is above the threshold value, then
it is turned white('1') and which are below the threshold value then they are turned black('0')
2. Gray-scale images
Grayscale images are monochrome images, Means they have only one color. Grayscale images do not
contain any information about color. Each pixel determines available different grey levels.
A normal grayscale image contains 8 bits/pixel data, which has 256 different grey levels. In medical
images and astronomy, 12 or 16 bits/pixel images are used.
3. Colour images
Colour images are three band monochrome images in which, each band contains a different color and
the actual information is stored in the digital image. The color images contain gray level information in
each spectral band.
The images are represented as red, green and blue (RGB images). And each color image has 24 bits/pixel
means 8 bits for each of the three color band(RGB).
8-bit color format
8-bit color is used for storing image information in a computer's memory or in a file of an image. In this
format, each pixel represents one 8 bit byte. It has 0-255 range of colors, in which 0 is used for black,
255 for white and 127 for gray color. The 8-bit color format is also known as a grayscale image. Initially,
it was used by the UNIX operating system.
16-bit color format
The 16-bit color format is also known as high color format. It has 65,536 different color shades. It is used
in the system developed by Microsoft. The 16-bit color format is further divided into three formats
which are Red, Green, and Blue also known as RGB format.
In RGB format, there are 5 bits for R, 6 bits for G, and 5 bits for B. One additional bit is added in green
because in all the 3 colors green color is soothing to eyes.
24-bit color format
The 24-bit color format is also known as the true color format. The 24-bit color format is also distributed
in Red, Green, and Blue. As 24 can be equally divided on 8, so it is distributed equally between 3
different colors like 8 bits for R, 8 bits for G and 8 bits for B.
Color Codes Conversion
Different color codes
As we know that color here is of 24-bit format, which means 8 bits of red, 8 bits of green, 8 bits of blue.
By changing the quantity of the 3 portions, you can made different colors.
Binary color format
Color: Black
Image:
Decimal code : RGB(0,0,0)
C++ vs Java
Explanation:
For pure black color, all the three portions of R, G, B is 0
Color: White
Image
Decimal : RGB(255, 255, 255)
Explanation:
For pure white color, all the three portions of R, G, B is 255
RGB color model
Color: Red
Image :
Decimal code: RGB(255, 0, 0)
Explanation:
For the red color, green and blue should be set 0, and for the red portion, we have to give its maximum
value, i.e. 255.
Color: Green
Image :
Decimal code: RGB(0, 255, 0)
Explanation:
For green color, red and blue should be set 0, and for the green portion, we have to give its maximum
value, i.e. 255.
Color: Blue
Image :
Decimal code: RGB(0, 0, 255)
Explanation:
For blue color, red and green should be set to 0, and for the blue portion, we have to give its maximum
value, i.e. 255.
Gray color
Color: gray
Image :
Decimal code: RGB(128, 128, 128)
Explanation:
For gray color, All the value should be 128.
CMYK color model
CMYK model is used for printers in which two carters are used, one for CMY color and other for black
color. CMY can be changed to RGB.
In CMYK color model C stands for cyan, M stands for magenta, Y stands for yellow, and K stands for
black.
Color: Cyan
Image :
Decimal code: RGB(0, 255, 255)
Explanation:
For cyan color, red should be set 0, and for the green and blue portion, we have to give its maximum
value, i.e. 255.
Color: Magenta
Image :
Decimal code: RGB(255, 0, 255)
Explanation:
For magenta color, green should be set 0, and for the red and blue portion, we have to give its maximum
value, i.e. 255.
Color: Yellow
Image :
Decimal code: RGB(255, 255, 0)
Explanation:
For magenta color, blue should be set 0, and for the red and green portion, we have to give its maximum
value, i.e. 255.
Color: Black
Image :
Decimal code : RGB(0,0,0)
Explanation:
For pure black color, all the three portions of R, G, B is 0
conversion happens by converting each color into 2 hexadecimal characters that represent it
Conversion
(255,255,255) is converted to #FFFFFF
RGB to Hex code
For example, if we want to convert the white color code (255, 255, 255) to hex code.
Following are the steps for RGB to Hex code conversion:
1. Taking the 1s portion i.e. value of red(R) 255.
2. Dividing it by 16. We will get 15 as a factor as well as remainder which is FF.
3. Repeat step 1 and 2 for another 2 portions.
4. Combine all the three hex code into one we will get #FFFFFF
Hex to RGB code
For example, if we want to convert white color code #FFFFFF
Following are the steps for converting hex code to RGB decimal format:
1. Divide the number into 3 equal parts: FF FF FF
2. Taking the 1st part and separating it: F F
3. Now convert each part into binary separately: (1111) (1111)
4. Combine both the binary values into one: 11111111
5. Now convert the binary number into a decimal number: 255
6. Now, repeat step 1 to 5 for another two portions.
7. Combine all the three hex code into one we will get (255, 255, 255)
Following are some colors and their hex code
Color Hex Code
Black #000000
White #FFFFFF
Gray #808080
Red #FF0000
Green #00FF00
Blue #0000FF
Cyan #00FFFF
Magenta #FF00FF
Yellow #FFFF00
Grayscale to RGB Conversion
To convert a grayscale image into color or RGB format, we have two methods. Both methods have their
advantages as well as disadvantages.
Methods for conversion of grayscale image to RGB are as following:
1. Average method
It is the simplest method. We have to take an average of all the 3 colors.
Formula: (R + G + B)/3
Java Try Catch
For example:
Explanation
As we can see, there are changes in the image by applying the average method. But the result is
unexpected as we want a grayscale image, but it turned to be a black image.
Problem
This problem occurs because we have taken an average of 3 colors. All the 3 colors have different
wavelength and have their contribution to the formation of an image. In the above image, we are taking
33% from each portion that is why the image does not occur in grayscale.
The solution to this problem is given by the weighted method.
Weighted method or luminosity method
As we have seen the problem in the average method. And for this problem weight method is the
solution. In all the 3 portions of color, red color has more wavelength, and green color has less
wavelength. But green color gives a more soothing effect to the eyes as compared to red color.
By decreasing the value of red color and increasing the value of green color and the value for blue color
will be between these two colors.
The equation for a new grayscale image will be:
Let the new grayscale image be X
According to the above equation, red is used 30%, green is used 59%, and blue is used 11%. The
contribution of green is highest.
By Applying the equation in an image, we will get:
Explanation
As we can see using the weighted method the image is properly converted into grayscale. Image is
brighter as compared with the image which was generated using the average method.