Image Edge Detection and Pseudo Color Generation Using MATLAB
OBJECTIVES
To use MATLAB functions for image edge detection.
To apply the pseudo colors to the grayscale image.
PROCEDURE:
Part A: Image Edge Detection
1. Laplacian of Gaussian filter smoothes the image to suppress noise before applying Laplacian operation for image edge detection. The image edge detection is to find the boundaries of objects in the image. The Laplacian of Gaussian filter could detect the horizontal and vertical boundaries as well as the boundaries other than the horizontal and vertical ones. Try the following MATLAB code:
%Laplacian filtering
K_size =5; % kernel size
SIGMA =0.9; % SIGMA parameter
h=fspecial('log',K_size,SIGMA); % determine the Laplacian filter kernel
image1_out=filter2(h,I); % perform filtering
image1_out=mat2gray(image1_out); % adjust range
image1_out=im2uint8(image1_out); % get the 8-bit image
figure,subplot(1,2,1); imshow(Y)
title('Original');
subplot(1,2,2); imshow(image1_out);
title('Laplacian of Gaussian filter 5x5 kernel');
Repeat (1) for the following different parameters and comment on your results.
K_size= 3, SIGMA=2,
K_size=10, SIGMA = 5
K_size =20, SIGMA =10
Part B: Pseudo Color Generation in Grayscale Image
In object detection, pseudo-color generation for a grayscale image can produce the specific color for the object that is to be detected such as the red color. This could significantly increase accuracy of the identification. For a grayscale image, choose three sine functions (others may also be possible) to transform the grayscale level to the red, green, and blue components as show in Figure below.
Figure 1
Obtain the grayscale image below:
[X, map]=imread('clipim2','gif');
Y=ind2gray(X,map); % 8-bit color image to the grayscale conversion
Study and try the following MATLAB program.
% apply pseudo color functions using sinusoids
C_r =304; % cycle change for the red channel
P_r=0; % phase change for the red channel
C_b=804; % cycle change for the blue channel
P_b=60; % phase change for the blue channel
C_g=304; % cycle change for the green channel
P_g=60; % phase change for the green channel
r=abs(sin(2*pi*[-P_r:255-P_r]/C_r));
g=abs(sin(2*pi*[-P_b:255-P_b]/C_b));
b=abs(sin(2*pi*[-P_g:255-P_g]/C_g));
figure, subplot(3,1,1);plot(r,'r');grid;ylabel('R value')
subplot(3,1,2);plot(g,'g');grid;ylabel('G value');
subplot(3,1,3);plot(b,'b');grid;ylabel('B value');
figure, imshow(Y);
map=[r;g;b;]'; % construct color map
figure, imshow(Y,map); % display pseudo color image
a. Modify the program by changing possible phase and cycle for each sine function so that the background to be green and the object (pointed by an arrow in the image) to be red. Comment on your results.
b. Change the color of the object (pointed by an arrow in the image) to be approximately green and the background to be blue. Comment on your results.
0 comments:
Post a Comment