Lab 1
Lab 1
Lab 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.
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
Morphological operations
Transforms
Image registration
Deblurring
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')
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')
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)
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')
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')
i=imread('testpat1.png');
j=imresize(i,1/4,'bicubic');
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')
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')
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')
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:
[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"---%
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---%
I=imread('cameraman.tif');
imwrite(I,'p.png')%---writes image with the specified extension type---%
imwrite(I,'p.tif')
imwrite(I,'p.jpg')
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')