You are on page 1of 16

Experiment-1

Date: 13/2/2013

20/2/2013

AIM:
(a) Introduction to image processing toolbox.

(b) To resize the image to see the resolution of pixels while keeping the
size of an image as it is.

(c) To read a color image and convert it to gray scale image, convert it to
gray scale image using map. Also convert a gray level image to index
image. Comment on the results.

(d) To read an RGB image, convert into YCbCr. Extract Y, Cb and Cr


components, resize them separately. Now, prove that we can reconstruct
RGB image using knowledge of Y, Cb and Cr components.

Goswami Pratikgiri R.(120420704006) Page 1


An image is worth a thousand words.

(a) Image Processing Toolbox

The Image Processing Toolbox software is a collection of functions that extend the capability of the
MATLAB numeric computing environment. The toolbox supports a wide range of image processing
operations, including

Spatial image transformations

Morphological operations

Neighborhood and block operations

Linear filtering and filter design

Transforms

Image analysis and enhancement

Image registration

Deblurring

Region of interest operations

Goswami Pratikgiri R.(120420704006) Page 2


(b) To resize the image to see the resolution of pixels while keeping the size of an image as it is.

i=imread('testpat1.png');
j=imresize(i,1/2,'nearest');
k=imresize(j,2,'nearest');
figure;
subplot(1,3,1)
imshow(i)
title('original image')
subplot(1,3,2)
imshow(j)
title('zooming by 2')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf NEAREST NEIGHBOR


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/2,'bilinear');
k=imresize(j,2,'bilinear');
figure;
subplot(1,3,1)
imshow(i)
title('testpat1.png')
subplot(1,3,2)
imshow(j)
title('zooming by 2')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf BILINEAR


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/2,'bicubic');
k=imresize(j,2,'bicubic');
figure;
subplot(1,3,1)
imshow(i)
title('testpat1.png')
subplot(1,3,2)
imshow(j)
title('zooming by 2')
subplot(1,3,3)

Goswami Pratikgiri R.(120420704006) Page 3


imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf BICUBIC


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/4,'nearest');
k=imresize(j,2,'nearest');
figure;
subplot(1,3,1)
imshow(i)
title('original image')
subplot(1,3,2)
imshow(j)
title('zooming by 4')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf NEAREST NEIGHBOR


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/4,'bilinear');
k=imresize(j,2,'bilinear');
figure;
subplot(1,3,1)
imshow(i)
title('testpat1.png')
subplot(1,3,2)
imshow(j)
title('zooming by 4')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf BILINEAR


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/4,'bicubic');

Goswami Pratikgiri R.(120420704006) Page 4


k=imresize(j,2,'bicubic');
figure;
subplot(1,3,1)
imshow(i)
title('testpat1.png')
subplot(1,3,2)
imshow(j)
title('zooming by 4')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf BICUBIC


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/8,'nearest');
k=imresize(j,2,'nearest');
figure;
subplot(1,3,1)
imshow(i)
title('original image')
subplot(1,3,2)
imshow(j)
title('zooming by 8')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf NEAREST NEIGHBOR


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/8,'bilinear');
k=imresize(j,2,'bilinear');
figure;
subplot(1,3,1)
imshow(i)
title('testpat1.png')
subplot(1,3,2)
imshow(j)
title('zooming by 8')
subplot(1,3,3)
imshow(k)
title('interpolated image')

Goswami Pratikgiri R.(120420704006) Page 5


ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0
4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf BILINEAR


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

i=imread('testpat1.png');
j=imresize(i,1/8,'bicubic');
k=imresize(j,2,'bicubic');
figure;
subplot(1,3,1)
imshow(i)
title('testpat1.png')
subplot(1,3,2)
imshow(j)
title('zooming by 8')
subplot(1,3,3)
imshow(k)
title('interpolated image')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0


4],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf BICUBIC


INTERPOLATION','HorizontalAlignment','center','VerticalAlignment', 'top')

Goswami Pratikgiri R.(120420704006) Page 6


Goswami Pratikgiri R.(120420704006) Page 7
Goswami Pratikgiri R.(120420704006) Page 8
Goswami Pratikgiri R.(120420704006) Page 9
Goswami Pratikgiri R.(120420704006) Page 10
(c) To read a color image and convert it to gray scale image, convert it to gray scale image
using map. Also convert a gray level image to index image. Comment on the results.

imread : reads an image in a matrix form

imshow and imview : displays image

rgb2gray : converts color image to 8-bit gray level image

im2bw : converts a grayscale image into a binary image

gray2ind : converts grayscale image to indexed image

Code:

clc;
clear all;
close all;
i=imread('football.jpg');%---reading an image---%
figure;
imshow(i)
g=rgb2gray(i);%---RGB to GRAY conversion---%
figure;
imshow(g);
b=im2bw(g)%---converting to binary image---%
figure;
imshow(b);
neg=255-g;%---negative image---%
figure;
imshow(neg)

Output:

Goswami Pratikgiri R.(120420704006) Page 11


clc;
close all;
clear all;
I=imread('cameraman.tif');
[X, map] = gray2ind(I,13)
figure;
imshow(X, map)

Goswami Pratikgiri R.(120420704006) Page 12


To read an image using map.

[X, map] = imread(...) reads the indexed image in filename into X and its associated colormap into
map. Colormap values in the image file are automatically rescaled into the range [0,1].

clc;
close all;
clear all;
[X, map] = imread('football.jpg');%---reading color image using "map"---%

Type conversion with example of addition of two images.

clc;
close all;
clear all;
i1=imread('cameraman.tif');
i2=imread('cameraman.tif');
i1=double(i1);%---converting to double---%
i2=double(i2);
i=imadd(i1,i2);
figure;
imshow(i)%---without converting again to uint8---%
figure;
imshow(uint8(i))%---after converting again to uint8---%

Goswami Pratikgiri R.(120420704006) Page 13


To study imwrite command.

I=imread('cameraman.tif');
imwrite(I,'p.png')%---writes image with the specified extension type---%
imwrite(I,'p.tif')
imwrite(I,'p.jpg')

Goswami Pratikgiri R.(120420704006) Page 14


(d) To read an RGB image, convert into YCbCr. Extract Y, Cb and Cr components, resize them
separately. Now, prove that we can reconstruct RGB image using knowledge of Y, Cb and Cr
components.

clc;
close all;
clear all;
RGB = imread('board.tif');
subplot(1,4,1)
imshow(RGB)
title('RGB image')
YCBCR = rgb2ycbcr(RGB);
subplot(1,4,2)
imshow(YCBCR)
title('YCbCr image')
y=YCBCR(:,:,1);
cb=YCBCR(:,:,2);
cr=YCBCR(:,:,3);

y1=imresize(y,2);
cb1=imresize(cb,2);
cr1=imresize(cr,2);

new(:,:,1)=y1;
new(:,:,2)=cb1;
new(:,:,3)=cr1;

subplot(1,4,3)
imshow(new)
title('doubled YCbCr image')

new1=ycbcr2rgb(new);
subplot(1,4,4)
imshow(new1)
title('doubled RGB image')

Goswami Pratikgiri R.(120420704006) Page 15


Conclusions:
Study of resizing i.e. Zooming and Shrinking implies that the method as well as the ratio by
which image is resized affects the results. So, zooming and shrinking are the subjective
processes based on the application.
Interpolating the same image does not give the results same as original one. That means
interpolation approximation must optimized in such a way that most of the information can
be obtained back.
Conversion of RGB to Gray, Gray to Binary show that RGB image contain three planes, each
for particular color map while gray scale image is 8 bit image. Binary image is 2 bit image or
a logical image.

Goswami Pratikgiri R.(120420704006) Page 16

You might also like