Professional Documents
Culture Documents
%Red Component
r=i(:,:,1);
subplot(3,2,2); imshow(r);title('Red Component');
%Green Component
g=i(:,:,2);
subplot(3,2,3); imshow(g); title('Green Component');
%Blue Component
b=i(:,:,3);
subplot(3,2,4); imshow(b); title('Blue Component');
2. Display color Image, find its complement and convert to gray scale
I=imread('cancercell.jpg');
subplot(2,2,1); imshow(I); subimage(I); title('Color Image');
c=imcomplement(I);
subplot(2,2,2); imshow(c); subimage(c); title('Complement of color Image');
r=rgb2gray(I);
subplot(2,2,3); imshow(r); subimage(r); title('Gray scale of color Image');
% Scaling (Resize)
I=imread('earcell.jpg');
subplot(2,2,1); subimage(I); title('Original Image');
% Rotation
K=imrotate(j,60);
subplot(2,2,3); imshow(K); title('Rotated Image 60deg');
R=imrotate(j,45);
subplot(2,2,4); imshow(R); title('Rotated Image 45deg');
5. Contrast stretching of a low contrast image, Histogram, and Histogram Equalization
% Image Enhancement
I=imread('cancercell.jpg');
subplot(4,2,1); imshow(I); title('Original Image');
g=rgb2gray(I);
subplot(4,2,5); imshow(g); title('Gray Image');
J=imadjust(g,[0.3 0.7],[]);
subplot(4,2,3); imshow(J); title('Enhanced Image');
m=histeq(g);
subplot(4,2,6); imshow(m); title('Equalized Image');
subplot(4,2,8); imhist(m); title('Histogram of Equalized Image');
6.Implementation of Non-Linear Filtering in Image
i= imread(‘filt.jpg’)
% Create a normalized 5-by-5 pixel averaging filter
h=ones(5,5)/25;
imf=imfilter(i,h);
ims=stdfilt(i);
ime=entropyfilt(i);
i1= imread(‘filt1.jpg’);
imr=rangefilt(i1);
i=imread('cancercell.jpg');
subplot(4,2,1); imshow(i);
title('Original Image');
g=rgb2gray(i);
subplot(4,2,2); imshow(g); title('Gray Image');
f=fspecial('laplacian',0.05);
im=imfilter(g,f);
subplot(4,2,3); imshow(im); title('Laplacian ');
s=edge(g, 'sobel');
subplot(4,2,4); imshow(s); title('Sobel');
p=edge(g, 'prewitt');
subplot(4,2,5); imshow(p); title('Prewitt');
r=edge(g, 'roberts');
subplot(4,2,6); imshow(r); title('Roberts');
[BW,thresh,gv,gh]=edge(g,'sobel',[],'horizontal');
[BW1,thresh1,gv1,gh1]=edge(g,'sobel',[],'vertical');
% 2D DFT of Image
i=imread(‘cup.jpg’);
i1=fft2(i);
i2=fftshift(i1);
i3=ifft2(i2);
RGB = imread('autumn.tif');
I = rgb2gray(RGB);
J = dct2(I);
J(abs(J)<10) = 0;
K = idct2(J);
% figure, imshow(I)
subplot(2,2,1),imshow(RGB),title('Original image');
subplot(2,2,2),imshow(I),title('grayscale image');
subplot(2,2,3),imshow(log(abs(J)),[]), colormap(jet), colorbar,title('colorbar for discrete
cosine transform');
subplot(2,2,4),imshow(K,[0 255]),title('inverse discrete cosine');
9. Implementation of image in Filtering frequency domain
clc;
clear all;
%% Loading Image
im=double(rgb2gray(imread('ffilt.jpg')));
F_u_v=fft2(im);
F_u_v=(fftshift(F_u_v));
figure(1);
subplot(1,2,1);imshow(uint8(im));
title('Original Image');
temp=log(abs(F_u_v));
subplot(1,2,2);
imshow(temp,[]);
title('Fourier Spectra');
%% Gaussian Filter
Hg = ifftshift(exp(-(D.^2)./(2*(D0^2))));
i=imread(‘c2.jpg’);
i2=rgb2ycbcr(i)
i3=rgb2ntsc(i);
i4=rgb2hsv(i);
2D Discrete Wavelet
load woman
imagesc(X)
colormap(map)
[cA,cH,cV,cD] = dwt2(X,'sym4','mode','per');
imagesc(cV)
title('Vertical Detail Coefficients')
imagesc(cA)
title('Approximation Coefficients')
2D Discrete Wavelet using Filters
load sculpture
imagesc(X)
colormap gray
[LoD,HiD] = wfilters('haar','d');
[cA,cH,cV,cD] = dwt2(X,LoD,HiD,'mode','symh');
subplot(2,2,1)
imagesc(cA)
colormap gray
title('Approximation')
subplot(2,2,2)
imagesc(cH)
colormap gray
title('Horizontal')
subplot(2,2,3)
imagesc(cV)
colormap gray
title('Vertical')
subplot(2,2,4)
imagesc(cD)
colormap gray
title('Diagonal')
12.Canny edge detection Algorithm
i= imread('cancercell.jpg');
g=rgb2gray(i);
subplot(2,2,1); imshow(i); title('Original Image');
subplot(2,2,2); imshow(g); title('Gray Image');
c=edge(g,'canny');
subplot(2,2,3); imshow(c); title('Canny output');