Digital Image Processing 2 nd ed www imageprocessingbook
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com MATLAB/Image Processing Toolbox HISTOGRAM EQUALIZATION >> f=imread(fig 3. 15(a). jpg’); >> imshow(f) >> figure, imhist(f) >> ylim(‘auto’) >> g=histeq(f, 256); >> >> hnorm=imhist(f). /numel(f); figure, imshow(g) figure, imhist(g) ylim(‘auto’) %load in figure 3. 15(a) % show figure in a new window % show histogram in a new window % histogram is not normalized. % set histogram tick marks and axis limits automatically % histogram equalize this figure % you can also do this with the cumsum function % computes normalized histogram % show this figure in a new window % generate a histogram of the equalized image % set limits again SEE GWE, Section 3. 3. 3 for a discussion of histogram specification using MATLAB © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com MATLAB/Image Processing Toolbox CORRELATION 1. f 00010000 v. CONVOLUTION w 12320 2. Alignment: 3. 00010000 12320 1. Now do zero padding: 2. 000000010000 12320 f 00010000 02321 0001000000010000 02321 ‘full’ correlation 000023210000 ‘full’ convolution 000123200000 ‘same’ correlation 00232100 ‘same” convolution 01232000 SEE GWE, Section 3. 4. 1 Linear Spatial Filtering, Figure 3. 13 © 2002 R. C. Gonzalez & R. E. Woods w rotated 180˚ 02321
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com MATLAB/Image Processing Toolbox LINEAR SPATIAL FILTERING >> f=imread(fig 3. 15(a). jpg’); %load in checkerboard figure % 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 >> w=ones(9); >> gd=imfilter(f, w); >> imshow( gd, [ ]) >> >> % create a 9 x 9 filter (not normalized) % filter using default values % [ ] 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 SEE GWE, Section 3. 4. 1 Linear Spatial Filtering © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com MATLAB/Image Processing Toolbox LINEAR SPATIAL FILTERING >> f=imread(fig 3. 15(a). jpg’); >> w=ones(9); %load in checkerboard figure % create a 9 x 9 filter (not normalized) % f is of type double in [0, 1] by default >> f 8=im 2 uint 8(f); % converts image to uint 8, i. e. , integers in range [0, 255] >> g 8 r=imfilter(f 8, w, ’replicate’); % pad using replication % imfilter creates an output of same data class as input, i. e. , uint(8) >> imshow( g 8 r, [ ]) % clipping caused data loss since filter was not % normalized SEE GWE, Section 3. 4. 1 Linear Spatial Filtering © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com MATLAB/Image Processing Toolbox MATLAB’s built-in filters >> f=imread(‘fig 3. 15(a). jpg’); %load in checkerboard figure >> w=fspecial(‘type’, parameters); % create filter mask % filter types: % ‘average’, default is 3 x 3 % ‘gaussian’, default is 3 x 3 and sigma=0. 5 % ‘laplacian, default alpha=0. 5 % ‘prewitt’, vertical gradient, default is 3 x 3. Get horizontal by wh=w’ % ‘sobel’, vertical gradient, default is 3 x 3 % ‘unsharp’, default is 3 x 3 with alpha=0. 2 SEE GWE, Section 3. 5 Image processing Toolbox Standard Spatial Filters © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com Chapter 3 Image Enhancement in the Spatial Domain © 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2 nd ed. www. imageprocessingbook. com MATLAB/Image Processing Toolbox PRODUCING FIGURE 3. 40 >> f=imread(‘Fig_Moon. jpg’); >> w 4=fspecial(‘laplacian’, 0) >> w 8=[1 1 1; 1 -8 1; 1 1 1] >>f=im 2 double(f); >> >> >> %load in lunar north pole image % creates 3 x 3 laplacian, alpha=0 [0: 1] % create a Laplacian that fspecial can’t % output same as input unit 8 so % negative values are truncated. % Convert to double to keep negative values. g 4=f-imfilter(f, w 4, ’replicate’); % filter using default values g 8=f-imfilter(f, w 8, ’replicate’); % filter using default values imshow(f) % display original image imshow(g 4) % display g 4 processed image imshow(g 8) % display g 8 processed image SEE GWE, Section 3. 5. 1 Linear Spatial Filters © 2002 R. C. Gonzalez & R. E. Woods
- Slides: 54