Presentation is loading. Please wait.

Presentation is loading. Please wait.

M ATLAB L ECTURE 3 Histogram Processing. H ISTOGRAM E QUALIZATION The imhist function create a histogram that show the distribution of intensities in.

Similar presentations


Presentation on theme: "M ATLAB L ECTURE 3 Histogram Processing. H ISTOGRAM E QUALIZATION The imhist function create a histogram that show the distribution of intensities in."— Presentation transcript:

1 M ATLAB L ECTURE 3 Histogram Processing

2 H ISTOGRAM E QUALIZATION The imhist function create a histogram that show the distribution of intensities in pout.tif. (figure command display the image a new window.) >>figure, imhist(I)

3 H ISTOGRAM E QUALIZATION The toolbox provides several ways to improve the contrast in an image. One way is to call the histeq function to spread the intensity values over the full range of the image, a process called histogram equalization. >>I2 = histeq(I);

4 H ISTOGRAM E QUALIZATION Display the new equalized image, I2, in a new figure window. >>figure, imshow(I2) Call imhist again to create a histogram of the equalized image I2. If you compare the two histograms, the histogram of I2 is more spread out than the histogram of I1. >>figure, imhist(I2)

5 E XAMPLE 2 As you see, the very dark image has a corresponding histogram heavily clustered at the lower end of the scale. But we can apply histogram equalization to this image, and display the results:

6 E XAMPLE 2 AFTER APPLYING HISTEQ >> ch=histeq(c); >> imshow(ch),figure,imhist(ch) results shown below:

7 L INEAR S PATIAL F ILTERING - S MOOTHING % g=imfilter(f,w,filtering_mode, boundary_options,size_options) % f is the input image % w is the filter mask % Filtering mode: % ‘corr’ filtering is done using correlation % ‘conv’ filtering is done using convolution -- flips mask 180 degrees % Boundary options % P without quotes (default) - pad image with zeros % ‘replicate’ - extend image by replicating border pixels % ‘symmetric’ - extend image by mirroring it across its border % ‘circular’ - extend image byrepeating it (one period of a periodic function) % Size options % ‘full’ - output is the same size as the padded image % ‘same’ - output is the same size as the input

8 L INEAR S PATIAL F ILTERING - S MOOTHING >> f=imread('GWFig3_41.jpg'); % or load in checkerboard figure 'Checker_Board.jpg' >> w=ones(9); % create a 9x9 filter (not normalized) >> gd=imfilter(f,w); % filter using default values >> imshow( gd, [ ]) % [ ] causes MATLAB to display using low and high gray levels of input image. Good for low dynamic range >> gr=imfilter(f,w,'replicate'); % pad using replication >> figure, imshow(gr, [ ]) >> gs=imfilter(f,w,'symmetric'); % pad using symmetry >> figure, imshow(gs, [ ]) % show this figure in a new window Try with a 3x3 filter of ones: w = ones(3); Try with a 3x3 filter of 1/9 (averaging): w = ones(3) / 9;

9 L INEAR S PATIAL F ILTERING - S HARPENING >> f=imread('GWFig3_41.jpg'); >> w= [-1,-1,-1; -1, 8,-1; -1,-1,-1]; % create a Laplacian filter >> lap_img =imfilter(f,w,'replicate'); % pad using replication >> figure, imshow(lap_img, [ ]) % show this figure in a new window % sharpen the image >> sh = f + lap_img; % sharpen the image by adding the image to its Laplacian >> figure, imshow(sh) % the sharpened image >> figure, imshow(f) % show the image for comparison

10 MATLAB’ S BUILT - IN FILTERS % w = fspecial(‘type’, parameters); % create filter mask % filter types: % ‘average’, default is 3x3 % ‘gaussian’, default is 3x3 and sigma=0.5 % ‘laplacian, default alpha=0.5 % ‘prewitt’, vertical gradient, default is 3x3. Get horizontal by wh=w’ % ‘sobel’, vertical gradient, default is 3x3 % ‘unsharp’, default is 3x3 with alpha=0.2

11 U SING MATLAB’ S BUILT - IN FILTERS >> f=imread('GWFig3_41.jpg'); %load in lunar north pole image >> w4=fspecial('laplacian',0) % creates 3x3 laplacian, alpha=0 [0:1] >> w8=[1 1 1;1 -8 1;1 1 1] % create a Laplacian that fspecial can’t >>f = im2double(f); % output same as input unit8 so % negative values are truncated. % Convert to double to keep negative values. >> g4=f-imfilter(f,w4,'replicate'); % filter using default values >> g8=f-imfilter(f,w8,'replicate'); % filter using default values >> imshow(f) % display original image >> figure, imshow(g4) % display g4 processed image >> figure, imshow(g8) % display g8 processed image


Download ppt "M ATLAB L ECTURE 3 Histogram Processing. H ISTOGRAM E QUALIZATION The imhist function create a histogram that show the distribution of intensities in."

Similar presentations


Ads by Google