0% found this document useful (0 votes)
69 views

DSP Lab6

Introduction to Image Processing (Multi-dimensional signal) lab manual
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

DSP Lab6

Introduction to Image Processing (Multi-dimensional signal) lab manual
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

LAB-6

1
LAB-6

2
LAB-6

3
Lab # 06 Introduction to Image Processing (Multi-
dimensional signal)
CONTENTS:

Objectives: ...................................................................................................................................... 5
Description: ..................................................................................................................................... 5
Sampling and Quantization ............................................................................................................. 5
• Types of images: ..................................................................................................................... 6
1. Binary Image:....................................................................................................................... 6
2. Grayscale Image: ................................................................................................................. 6
3. RGB Image: ......................................................................................................................... 6
Syntax: .................................................................................................................................... 6
4. Hyperspectral Image: ........................................................................................................... 6
• Reading an Image: ............................................................................................................... 6
Syntax: .................................................................................................................................... 6
Description: ............................................................................................................................. 7
• Display an Image: ................................................................................................................ 7
Syntax: .................................................................................................................................... 7
Description: ............................................................................................................................. 7
• Writing Image Data: ............................................................................................................ 7
Syntax: .................................................................................................................................... 7
Example: ................................................................................................................................. 7
• No. of rows and columns of image: ..................................................................................... 7
Syntax: .................................................................................................................................... 7
• Pixel Value(intensity/data): ................................................................................................. 8
• Gray scale image to black n white ....................................................................................... 8
Syntax: .................................................................................................................................... 8
• Mirror Image Generation in MATLAB: .............................................................................. 8
LAB TASKS: .............................................................................................................................. 9

4
Introduction:

Objectives:
At the end of this lab students are able to read and display the image in MATLAB. They are also able to
access the image pixels to generate the mirror and flipped images of the provided image.

Description:
An image is nothing more than a two-dimensional signal. It is defined by the mathematical function f (x,
y) where x and y are the two co-ordinates horizontally and vertically. The value of f (x, y) at any point
gives the pixel value at that point of an image.

The above figure is an example of digital image that you are now viewing on your computer screen. But
actually, this image is nothing but a two-dimensional array of numbers ranging between 0 and 255.
128 30 123

232 123 321

123 77 89

80 255 255

Sampling and Quantization


In order to become suitable for digital processing, an image function f (x, y) must be digitized both spatially
and in amplitude. Typically, a frame grabber or digitizer is used to sample and quantize the analogue video
signal. Hence in order to create an image which is digital, we need to covert continuous data into digital
form. There are two steps in which it is done:
1. Sampling
2. Quantization
The sampling rate determines the spatial resolution of the digitized image, while the quantization level
determines the number of grey levels in the digitized image. A magnitude of the sampled image is expressed
as a digital value in image processing. The transition between continuous values of the image function and
its digital equivalent is called quantization.

5
The number of quantization levels should be high enough for human perception of fine shading details in
the image. The occurrence of false contours is the main problem in image which has been quantized with
insufficient brightness levels.

• Types of images:

1. Binary Image:
In binary images, the pixel value is either 0 or 1, which makes it just black and white image i.e. it is just
two levels quantized.

2. Grayscale Image:
In Grayscale image, the pixel value is quantized to 8-bits, 256 levels in between 0 and 1. This 8-bits, 256
leveled imaged is suitable for human eye to recognize the difference between different color shades.

3. RGB Image:
RGB image stands for RED-GREEN-BLUE image. This is a colored image which holds three different
colored bands. Almost all colors can be designed from the combination of these three basic color units.

Syntax:
A(2,3,2) means 2nd row, 3rd column pixel of 2nd band (green band).
A(:,:,3) gives you complete third band(blue band).

4. Hyperspectral Image:
Hyperspectral images contain 100’s of bands in a single image and usually are satellite images.

• Reading an Image:
To import an image from any supported graphics image file format, in any of the supported bit depths, use
the imread function.

Syntax:
A = imread(filename,fmt)

6
Description:
A = imread(filename,fmt) reads a greyscale or color image from the file specified by the string filename,
where the string fmt specifies the format of the file i.e. .jpg or .tif. If the file is not in the current directory
or in a directory in the MATLAB path, specify the full pathname of the location on your system.

• Display an Image:
To display image, use the imshow function.

Syntax:
imshow(A)

Description:
imshow(A) displays the image stored in array A.

• Writing Image Data:


Write image to graphics file

Syntax:
imwrite(A,filename,fmt)

Example:
a=imread('pout.tif'); %tif image

imwrite(a,gray(256),'b.bmp'); % image ‘a’ is written as bmp image

imshow('b.bmp') % imshow is used to display image

• No. of rows and columns of image:


Function size gives the rows and columns dimension of image

Syntax:
[r,c]=size(a)

7
• Pixel Value(intensity/data):
There is a one-to-one correspondence between pixel coordinates and the coordinates MATLAB® uses for
matrix subscripting. This correspondence makes the relationship between an image's data matrix and the
way the image is displayed easy to understand. For example, the data for the pixel in the fifth row, second
column is stored in the matrix element (5,2). You use normal MATLAB matrix subscripting to access
values of individual pixels.
For example, the MATLAB code A (2, 15) returns the value of the pixel at row 2, column 15 of the image
A.

• Gray scale image to black n white


Grayscale image having pixel values from 0-255 can be converted to 0-1.

Syntax:
BW = im2bw (I, LEVEL) converts the intensity image I to black and white.

• Mirror Image Generation in MATLAB:


% this program produces mirror image of the image passed to it n also
% displays both the original and mirror image
a=imread('cameraman.tif'); %built-in demo image (gray scale image in MATLAB

[r,c]=size(a);

for i=1:1:r

k=1;

for j=c:-1:1

temp=a(i,k);

result(i,k)=a(i,j);

result(i,j)=temp;

k=k+1;

end

end

subplot(1,2,1), imshow(a)

subplot(1,2,2),imshow(result)

8
LAB TASKS:

TASK-1: Design a MATLAB code that reads any RGB image of your choice, then convert it
into gray scale image using ‘rgb2gray’ MATLAB command. Afterwards, take the converted gray
scale image and transform into binary image. You are also required to display R, G, and B bands
of RGB image individually.

TASK-2: Write a MATLAB code that reads a gray scale image and generates the flipped image of
original image. Your output should be like the one given below at the right side of image. The image
provided in the image is the built-in demo image (gray scale image) of MATLAB named ‘pout.tif’.

9
TASK-3: Write a MATLAB code that reads and displays a gray scale image. Then, again display the
image such that the pixels having intensity values below than 50 will display as black and pixels having
intensity values above than 150 will display as white. And the pixels between these will display as it
is.

10

You might also like