Lab1

advertisement
Digital
Image
Processing
Lecturer Mohd Abdul Rahim Khan
February 8
2015
CEN446
Fundamental
of image
1. To write a program to read an image and display it in double precision.
clc;
A = imread('India.jpg');
A= im2double(A);
imshow(A)
2. To write a program to display a magic square as an image.
clc;
A = magic(100)
I = im2double(A);
imshow(I)
3. To write a program to display an image and its histogram.
clc;
A=imread('shivani.jpg');
I=rgb2gray(A);
I=im2double(I);
imshow(I)
figure,
imhist(I)
4. To write a program to learn basic functions of DIP in MATLAB.
clc;
close all;
clear all;
% A = imread(filename, fmt)
% It reads a grayscale or color image from the file specified by the string filename. % And display
it in the matrix form. Each element of a matrix show the intensity of that pixel.
5.
To write a program to read an image and write the image
A=imread('lena.tif');
figure
subplot(221)
imshow(A);
title('Read an image and show');
% imwrite(A,filename,fmt)
% It writes the image to filename, inferring the format to use from the filename's extension.
imwrite(A,'E:\abc.jpg');
subplot(222)
imshow('E:\abc.jpg');
title('Write an image and show');
% I = mat2gray(A, [amin amax]) % Convert matrix to grayscale image.The returned matrix I
contains values % in the range 0.0 (black) to 1.0 (full intensity or white). % amin and amax are
the values in A that correspond to 0.0 and 1.0 in I.
B=mat2gray(A,[100,150]);
subplot(223) imshow(B);
title('mat2gray');
% Z = imsubtract(X,Y) % Subtract one image from another or subtract constant from image
C=imsubtract(A,100);
subplot(224) imshow(C);
title('Image subtracted from constant');
% IM2 = imcomplement(IM) % It computes the complement of the image IM. IM can be a
binary, grayscale, or RGB image. 13 % IM2 has the same class and size as IM.
6. Write a program to complement of the image
D=imcomplement(A);
figure subplot(121)
imshow(D);
title('Complemented image');
% B = imrotate(A,angle) % It rotates image A by angle degrees in a counterclockwise direction
around its center point. To rotate the image clockwise, % specify a negative value for angle.
imrotate makes the output image B large enough to contain the entire rotated image. %
imrotate uses nearest neighbor interpolation, setting the values of pixels in B that are outside
the rotated image to 0 (zero).
7. Write a program to Divide one image into another or divide image by
constant
E=imrotate(A,-90);
subplot(122)
imshow(E);
title('Image rotated by 90');
% Z = imdivide(X,Y)
% Divide one image into another or divide image by constant
8. Write a program to multiply two images or multiply image by constant
I = imread('India.jpg');
J = imdivide(I,2);
figure subplot(121),
imshow(I)
title('Original image');
subplot(122),
imshow(J)
title('Image divided by constant');
% Z = immultiply(X,Y) % Multiply two images or multiply image by constant
W = imread('shivani.jpg');
Z = immultiply(W,0.5);
figure subplot(121),
imshow(W)
title('Original image');
subplot(122),
imshow(Z)
title('Image multiplied by constant');
9. To write a program to rotate an image.
a = imread('shivani.jpg');
figure
subplot(4,2,[1 2])
imshow(a)
title('Original')
b = imresize(a,[4,4])
subplot(4,2,3)
imshow(b)
title('Resize 4x4')
c = imresize(a,[128,128])
subplot(4,2,4)
imshow(c)
title('Resize 128x128')
d = imrotate(a,60) subplot(4,2,5)
imshow(d)
title('Rotated by 60')
e = im2bw(a,0.6)
subplot(4,2,6)
imshow(e)
title('Binary')
f=rgb2ind(a,32);
subplot(4,2,6)
imshow(f);
title('Array Indexing')
g=rgb2gray(a)
subplot(4,2,7)
imshow(g)
title('Grayscale');
10.To write a program for mirror image generation
clc;
% this program produces mirror image of the image passed to it
% and also displays both the original and mirror image
a=imread('pout.tif');
[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)
Download