The mission is to practice using histogram function in MATLAB,
In this MATLAB code turorial, we choose a gray level Lena image. Of course, you can use any picture you want.
Here are three practices we are going to do
(a)
Compute and plot its histogram.
(b)
Apply histogram equalization to obtain a
transformed image.
(c)
Apply Canny’s edge detection method to the
given image (with two sigma
values of the Gaussian filter) to show the
two edge maps that you obtain.
Procedure:
Practice (a)
By using the function ‘imhist’, a histogram of Lena can be shown. This histogram shows that the image has dark pixel rather than bright pixel. And there is no extremely bright pixels shown in this picture.
Practice (b)
By calling the function ‘histeq’, the original image is adjusted to the one with obvious contrast. There are more white pixels shown in the new image. Besides, it is easier to identify every single part from the new image.
Practice (c)
At first, we apply 2 kinds of Gaussian filters with different sigma to the image. And then use Canny’s edge detection method on them. According to the theory, the bigger the sigma, more blurred will be the image. And it is also validated by the result shown above. From the picture we can see that the image with lower sigma can be identified more boundaries and edges. The image with higher sigma cannot be detected much silhouette.
Let's see how do we complete it by useing Matlab :)
Let's see how do we complete it by useing Matlab :)
1: %%
2: %%%%%%%%%%%%%%%%%%%%%%% (a) Compute and plot its histogram. %%%%%%%%%%%%%%%%%%%%%%%
3: im_GrayLena=imread('431.JPG'); % read image
4: %figure,imshow(im_GrayLena); % show image
5: %title('gray Lena'); % imgae title gray_lena
6: twoD_Lena=rgb2gray(im_GrayLena); %convert to 2D
7: figure,imhist(twoD_Lena); % process histogram and show
8: title('Histogram of Lena')
9: xlabel('Grayvalue')
10: ylabel('Probality Of Occurence')
11: %%
12: %%%%%%%%%%%%%%%%%%%%%%% (b) Apply histogram equalization to obtain a transformed image. %%%%%%%%%%%%%%%%%%%%%%%
13: histeq_lena = histeq(twoD_Lena); % histogram equalization
14: figure, imshow(histeq_lena) % show image after histogram equalization
15: title('Lena after Equalization')
16: figure,imhist(histeq_lena);
17: title('Histogram of Lena after Equalization') % Histogram of Lena after Equalization
18: xlabel('Grayvalue')
19: ylabel('Probality Of Occurence')
20: %%
21: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22: %%%%%%%%%%%%%%%%(c)Apply Canny’s edge detection method to the given image %%%%%%
23: %%%%%%%%%%%%%%%% (with two sigma values of the Gaussian filter)to show the two edge maps that you obtain.%%%%%%
24: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25: I=twoD_Lena;
26: Iblur02 = imgaussfilt(I, 0.2);
27: figure,imshow(Iblur02);
28: title('Guassian Sigma=0.2');
29: BW_canny02=edge(Iblur02,'canny');
30: figure,imshow(BW_canny02);
31: title('Guassian&canny edge Sigma=0.2');
32: Iblur4 = imgaussfilt(I, 4);
33: figure,imshow(Iblur4);
34: title('Guassian Sigma=4');
35: BW_canny4=edge(Iblur4,'canny');
36: figure,imshow(BW_canny4);
37: title('Guassian&canny edge Sigma=4');
38: %figure;
39: %imshowpair(BW_canny1,BW_canny4, 'diff')
The result is shown below
Please email me if you have any question
Email: HSC38@pitt.edu







