digital image processing

by

 

some coding about dip

dip_assignment01.m
imadress='C:\DIP_assignment\ori_images\ching_on_hua\hua1.jpg';%original image location
location='C:\DIP_assignment\After_processing\';%save location(have to create folder by self)
folder1='ching_on_hua\';%subfolder name
picname = 'hua1';%save as picture name
%original image
I=imread(imadress);%original picture function
Img=imresize(I,0.25);%image is resized to provide better process
figure,imshow(Img);
title('original image')
saveas(1, [location folder1 'original\' picname '.jpg']);
%gray image
Gr=rgb2gray(Img);%gray picture function
figure,imshow(Gr);
title('Gray')
saveas(2,[location folder1 'gray\' picname '.jpg']);
%graph of gray level
figure, imhist(Gr)
title('Histogram of gray level')
saveas(3,[location folder1 'Histogram_of_gray_level\' picname '.jpg']);
%histogram equalization
he = histeq(Gr);%histogram equalization function 
figure,imshow(he);
title('histogram equalization')
saveas(4,[location folder1 'histogram_equalization\' picname '.jpg']);
%graph of histogram equalization
figure, imhist(he)
title('Histogram After histogram equalization')
saveas(5,[location folder1 'graph_histogram_equalization\' picname '.jpg']);
%RGB image
rgb=Img;%rgb image is same with original image
figure,imshow(rgb);
title('RGB image')
saveas(6,[location folder1 'RGB_image\' picname '.jpg']);
figure,imshow(rgb(:,:,1));
title('R image')
saveas(7,[location folder1 'RGB_image\R\' picname '.jpg']);
figure,imshow(rgb(:,:,2)); 
title('G image')
saveas(8,[location folder1 'RGB_image\G\' picname '.jpg']);
figure,imshow(rgb(:,:,3));
title('B image')
saveas(9,[location folder1 'RGB_image\B\' picname '.jpg']);
%HSI image
rgb = im2double(rgb);
r = rgb(:, :, 1); 
g = rgb(:, :, 2); 
b = rgb(:, :, 3); 
    %Implement the conversion equations. 
num = 0.5*((r - g) + (r - b)); 
den = sqrt((r - g).^2 + (r - b).*(g - b)); 
theta = acos(num./(den + eps)); 
H = theta; 
H(b > g) = 2*pi - H(b > g); 
H = H/(2*pi); 
figure,imshow(H);
title('H')
saveas(10,[location folder1 'HSI_image\H\' picname '.jpg']);
num = min(min(r, g), b); 
den = r + g + b; 
den(den == 0) = eps; 
S = 1 - 3.* num./den; 
figure,imshow(S);
title('S')
saveas(11,[location folder1 'HSI_image\S\' picname '.jpg']);
H(S == 0) = 0; 
I = (r + g + b)/3; 
figure,imshow(I);
title('I')
saveas(12,[location folder1 'HSI_image\I\' picname '.jpg']);
hsi = cat(3, H, S, I);
figure,imshow(hsi);
title('HSI')
saveas(13,[location folder1 'HSI_image\' picname '.jpg']);
%CMY image
cmy=imcomplement(Img);%CMY function
figure,imshow(cmy);
title('CMY')
saveas(14,[location folder1 'CMY_image\' picname '.jpg']);
figure,imshow(cmy(:,:,1))
title('C')
saveas(15,[location folder1 'CMY_image\C\' picname '.jpg']);
figure,imshow(cmy(:,:,2))
title('M')
saveas(16,[location folder1 'CMY_image\M\' picname '.jpg']);
figure,imshow(cmy(:,:,3))
title('Y')
saveas(17,[location folder1 'CMY_image\Y\' picname '.jpg']);
%edge detection
sobel=edge(Gr,'sobel');%edge sobel function
figure,imshow(sobel);
title('Sobel');
saveas(18,[location folder1 'Edge\Sobel\' picname '.jpg']);
canny=edge(Gr,'canny');%edge canny function
figure,imshow(canny);
title('Canny');
saveas(19,[location folder1 'Edge\Canny\' picname '.jpg']);
roberts=edge(Gr,'roberts');%edge roberts function
figure,imshow(roberts);
title('Roberts');
saveas(20,[location folder1 'Edge\Roberts\' picname '.jpg']);
log=edge(Gr,'log');%edge log function
figure,imshow(log);
title('Log');
saveas(21,[location folder1 'Edge\Log\' picname '.jpg']);
prewitt=edge(Gr,'prewitt');%edge prowitt function
figure,imshow(prewitt);
title('Prewitt');
saveas(22,[location folder1 'Edge\Prewitt\' picname '.jpg']);
zerocross=edge(Gr,'zerocross');%edge zerocross function
figure,imshow(zerocross);
title('Zerocross');
saveas(23,[location folder1 'Edge\Zerocross\' picname '.jpg']);
%FFT function
fft = fft2((Gr));
figure, imshow(abs(fftshift(fft)),[1 10000]), colormap gray
title('FFT 1')
saveas(24,[location folder1 'FFT\' picname '.jpg']);

close all;

Contact us