1. Lecture 2: Image types and formats
Computer Vision In MATLAB
By. Assist. Prof. Ielaf O.Abdul Majjed
2022-2023
2. Concept of Bits Per Pixel
bits per pixel (BPP) denotes the number of bits per pixel. The number of different colors in an image is depends
on the depth of color or bits per pixel. f we devise a formula for the calculation of total number of combinations
that can be made from bit, it would be like this.
Put 1 in the formula you get 2, put 2 in the formula, you get 4. It grows exponentially.
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)
This table shows different BPP and the amount of color they contain.
In case of 1 bpp, 0 denotes black, and 1 denotes white.
In case 8 bpp, 0 denotes black, and 255 denotes white.
3. The size of an image depends upon three things.
Number of rows
Number of columns
Number of bits per pixel
The formula for calculating the size is Size of an image = rows * cols * bpp
Image storage requirements
Assuming it has 1024 rows and it has 1024 columns. And since it is a gray scale image, it has 256 different
shades of gray or it has bits per pixel. Then putting these values in the formula, we get
Size of an image = rows * cols * bpp
= 1024 * 1024 * 8
= 8388608 bits.
But since its not a standard answer that we recognize, so will convert it into our format.
Converting it into bytes = 8388608 / 8 = 1048576 bytes.
Converting into kilo bytes = 1048576 / 1024 = 1024kb.
Converting into Mega bytes = 1024 / 1024 = 1 Mb.
If you are given the size of the image and the bpp, you can also compute the rows and columns of a
square image using the formula (same rows and same column).
4. The distribution of colors within images may take numerous forms.
Type of an Image
1.BINARY IMAGE: The binary image as its name suggests, contain only two pixel
elements 0 & 1,where 0 refers to black and 1 refers to white. This image is also
known as Monochrome or bi-level image.
For converting an image into a binary image must choose a threshold value:
If f(x,y) in Image is greater than or equal to the threshold, Then set f(x,y) = 255
If f(x,y) is less than to the threshold Then set f(x,y)=0.
2. GRAY LEVEL (SCALE) 8 BIT COLOR FORMAT
8 bit color format is one of the most famous image format Each pixel is
represented by a single byte(8bit). It has 256 different shades of colors in it. It is
commonly known as Grayscale image. The range of the colors in 8 bit vary from
0-255. Where 0 stands for black, and 255 stands for white, and 127 stands for
gray color. Requires Color Look-Up Tables (LUTs) – Palette where the value of R
& G & B in (LUTs) are equal.
5. 3. COLOR IMAGES
• 8 bit color image (index color).
• 16 bit Hicolor.
• 24 bit color image.
• 23 bit color image.
8 bit color image (index color).
Each pixel used 8-bits to indicate the desired color. This number is then used as an index into
a hardware table called the color palette that contains 256 entries, each holding a 24-bit RGB
value. This is called indexed color.
This technique is also called pseudocolor.
Since humans are more sensitive to R and G than to B, we could use 3 bits for R and G,and 2
bits for B in index color.
Requires Color Look-Up Tables (LUTs) – Palette.
16-bit Hicolor images
The hicolor which uses 16 bits per pixel (5 R, 6 G, 5 B or 5 for each with 1 bit unused or 6R, 6G ,4B).
The maximum number of colors in 16 bit color image is 216 Color.
The palette does not affect the images.
6. 24-bit color image
In a 24-bit color image, each pixel is represented by three bytes, usually representing RGB.
The maximum number of colors in 24bit color image is 224 or (16,777,216).
Such graphics are referred to as “True Color" images, or just as "24-bit"graphics.
If the browser is in 24-bit display, the palette does not affect the images.
32-bit color images
The 32-bit color images are actually stored as 32-bit (RGBA) images, with the extra byte of data
for each pixel used to store an alpha value representing special effect information
If the browser is in 32-bit display, the palette does not affect the images.
Each pixel is represented by four byte(32bit).
7. All the colors here are of the 24 bit format, that means each color has 8 bits of red, 8 bits of green, 8 bits of
blue, in it. Or we can say each color has three different portions. You just have to change the quantity of these
three portions to make any color.
Binary color format
Color: Black Decimal Code: (0,0,0)
if we have to make a pure black color, we have to make all the three portion of R, G, B to 0.
Color: White Decimal Code: (255,255,255)
Color: Red Decimal Code: (255,0,0)
Color: Green Decimal Code: (0,255,0)
Color: Blue Decimal Code: (0,0,255)
Color: Gray Decimal Code:(128,128,128)
H.W.
1- Convert color images to gray using the equation and then using RGB2gray.
2- Zooming image.
Different color codes
8. Image Formats
Image Format describes how data related to the image will be stored. Data can be stored in compressed,
Uncompressed or vector format. Each format of the image have a different advantage and disadvantage.
Image types such a TIFF are good for printing while JPG or PNG, are best for web.
Many image formats adhere to the following simple model:
Header
Data (line by line, no breaks between lines).
Header contains at least: A signature or “magic number” (i.e. a short sequence of bytes for identifying
the file format) and the width and height of the image.
9. TIFF(.tif, .tiff) Tagged Image File Format this format store image data without losing any data. It do
not perform any compression on images have a high-quality image is obtained but size of image is
also large, which is good for printing, professional printing.
JPEG (.jpg, .jpeg) Joint Photographic Experts Group is a loss-prone (lossy) format in which data
is lost to reduce size of image. Due to compression, some data is lost but that loss is very less. It is a
very common format and are good for digital cameras, nonprofessional prints, E-Mail, Powerpoint
etc., making it ideal for web use.
GIF (.gif) Graphics Interchange Format files are used for web graphics. They can be animated and
are limited to only 256 colors, can allow for transparency. GIF files are typically small is size and are
portable.
PNG (.png) Portable Network Graphics files are a lossless image format. It was designed to
replace gif format as gif supported 256 colors unlike PNG which support 16 million colors.
Bitmap (.bmp) Bit Map Image file is developed by Microsoft for windows. It is same as TIFF due
lossless, no compression property. Due to BMP being a proprietary format, it is generally
recommended to use TIFF files.
EPS (.eps) Encapsulated PostScript file is a common vector file type. EPS files can be opened in
applications such as Adobe Illustrator or CorelDRAW.
RAW Image Files (.raw, .cr2, .nef, .orf, .sr2) These Files are unprocessed created by a camera or
scanner. Many digital SLR cameras can shoot in RAW, whether it be a .raw, .cr2, or .nef. These
images are the equivalent of a digital negative, meaning that they hold a lot of image information.
These images need to be processed in an editor such as Adobe Photoshop or Lightroom. It saves
metadata and is used for photography.