0% found this document useful (0 votes)
17 views12 pages

Expt1 Iplab

The document discusses manipulating a BMP image file by reading the file, modifying color channels by setting them to zero, and writing the output. It provides code to read the header, load pixel data, modify a channel, and write the new file. Sample outputs are shown for setting each color channel of an image to zero.

Uploaded by

vikasvikas017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views12 pages

Expt1 Iplab

The document discusses manipulating a BMP image file by reading the file, modifying color channels by setting them to zero, and writing the output. It provides code to read the header, load pixel data, modify a channel, and write the new file. Sample outputs are shown for setting each color channel of an image to zero.

Uploaded by

vikasvikas017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Department of Electronics &


Electrical Communication Engineering

Dual degree 4th year

Vision And Intelligent Systems

EC69505 – Digital Image And Video Processing Laboratory


Submitted by

G.vinay venkata sai - 19EC39012


Vishrut kumar - 19EC39040

Contents

1. Introduction
2. Algorithm
3. Output Results
4. Discussion
5. References
INTRODUCTION

This experiment aims to read a Bitmap image file (grayscale or


RGB), convert it to a grayscale image if it isn't already grayscale,
manipulating the color channel of the corn.bmp file, and
modifying the R or G or B any one of the channel to zero, and then
write it to the disc as an image.

This experiment was done with python using colab, in order to


understand how image files are created and how they are
manipulated and operated upon.

Bitmap or BMP files are quite old file formats used by the
”Windows” operating system. BMP images can range from 1 bit per
pixel (thus a black and white image) to 24 bits per pixel (providing
1.67 million colors). In the experiment we used an 8 bits per pixel
(Grayscale image) and 12 bits per pixel (RGB color image) formats
for operating upon. Following are two parts of a BMP file:

Header: It contains information about file and image. This part can
be broken into two parts:
(a) File Header, which contains general information related to the
file like type of the image file ( BM for the Bitmap file) and Size of
the file. Other fields are reserved and are not to be edited by the
user.
(b) Information Header( BITMAPINFOHEADER) , which contains
information about the image, like Width, Height and Bits per pixel
among other data
2. Image Data: It contains the pixel data or the color table
contents which are to be manipulated to transform the image. The
data starts from the address stored in the offset field of the
BITMAPINFOHEADER. It was observed that for grayscale images,
the offset was generally 1078, while for RGB color images it was 54.
The data is stored Bottom-to-Top and Left-to-Right, i.e. the data is
stored in rows which start filling at bottom first and then keep
filling to the top. The row size(in bytes) should be divisible by 4,
otherwise it should be padded with zeros such that the row size
become divisible by 4.

RowSize = [BitsPerPixel·ImageWidth+31/ 32 ]· 4
For flipping, contents are swapped about the diagonal of the
image data while, for the color to grayscale conversion, grayscale
value is calculated as,

Grayscale = R × 0.30 + G × 0.59 + B × 0.11

Color Pallet: This block contains the list of colors to be used by a


pixel. This is an indexed table with the index starting from 0.
However, this block is mandatory when BitsPerPixel is less than or
equal to 8, hence this block is semi-optional. When the
BitsPerPixel is 16, 24, or 32, the color value of a pixel is calculated
from the combination of individual Blue, Green, and Red values
defined by the pixel.

Algorithm

The header is saved in a data structure and the image data is


loaded into memory after dynamic allocation of the memory.
1: Reading the header
2: Allocating size to the array according to the information given in
the header
3: Loading the data in the memory
4: Return header During these operations, we also read the data
that may appear as unknown
5.We stored different values including offset,width,height,bitWidth
etc.
6.We got to know the number of bits per pixel from the Header
Structure.
7.For images which are colored and whose bits per pixel is > 8 ,we
got rgb sets.
8.If not colored, there won't be any color table
9.For writing, we created a new file and loaded the header file first
and then the pixel array we got from the read operation.
10.For the third part, we are reading the corn.bmp image and
making the component of red 0 and then blue 0 and then green
0.
11.Then we are creating a new file to which we are loading the
updated color table values.

Color Channel Manipulation:

● First, we read the input corn image file. Then we find the
information about the header.
● Since it is an 8-bit image then we allocate 256 x 4 size to the
extra variable to store the color table data.
● Then we call the write function and while writing the data from
extra we make one of the channels say Blue = 0 and store the
intensities of other channels as it is.
●Finally, we write the data in the final output image
“Cornupdated”.

Output Results

Part-1
Part-2
These are the following results when we give input file as
corn.bmp,cameraman.bmp,lena_coloured_256.bmp respectively

Part-3
These are the results when

Output corn image(Blue=0)


Output corn image (Green=0)
Output corn image (Red=0), respectively

Discussion
The BMP file format, also known as bitmap image file or device
independent bitmap (DIB) file format or simply a bitmap, is a
raster graphics image file format used to store bitmap digital
images, independently of the display device.

BMP file format is well defined, the file format consists of file
header, information header, and the pixel array. BMP file header
gives important information such as height, width, size, offset and
number of bits per pixel.

Pixel array starts from a different location in case of


Red-Blue-Green(RGB) images and Grayscale images. In case of
RGB image the pixel array location is from 54 where as in case of
Gray-scale images it is from 1078.

The size of images can be calculated as Header Size +


Channels*Height*Width This holds true in case of RGB i.e.
54+3*512*512 which is equal to size of the image, but in case of
some gray-scale the calculated size i.e. 1078 + 512*512 and the
actual size has a difference of two bytes.

To set the intensity zero of any of the colors in the corn image we
have assigned value 0 to a particular column of a color table and
increased our pointer by 4 to reach the next element of the same
column.

Therefore, for output images we have used the same file header
and just altered the pixel array, rest of the file data has been copied
as it is.
References

BMP image format, Paul Bourke, July 1998


http://paulbourke.net/dataformats/bmp/

You might also like