Fundamentals of Computer Vision Lecture 4 Dr. Roger S. Gaborski Roger S. Gaborski 1 QUIZ 1 Closed book except one page of handwritten notes Roger S. Gaborski 2 Intensity Transformation and Spatial Transformation • Intensity – modify each pixel in the image independent of its neighbors • Spatial – modify a pixel as a function of its neighbors (spatial convolution) Roger S. Gaborski 3 If you look at a pixel of an intensity (gray level image- Next Slide) in isolation what can you tell me about the image? Roger S. Gaborski 4 Roger S. Gaborski 5 If you look at a pixel of an intensity (gray level image- Next Slide) in isolation what can you tell me about the image? The brightness or intensity value at that spatial location Roger S. Gaborski 6 What if you inspect a neighborhood of pixel values? Roger S. Gaborski 7 Depends on the neighborhood Sky Region Flag Region (2 rows, 3 columns) The ‘flag region’ contains more information about the image – There is a horizontal line in this region Roger S. Gaborski 8 Can we modify the intensity values to change the image (improve in some way) or extract information from the image (edges, shapes, etc.)? Roger S. Gaborski 9 Spatial Transformation • The general spatial domain processing equation: g(x, y) = T [ f (x, y)] – f (x, y) is the input image – g(x, y) is the output image – T is an operator on f defined over a specific neighborhood Roger S. Gaborski 10 Chapter 3 www.prenhall.com/gonzalezwoodseddins - Define spatial neighborhood about a point, (x, y) - Neighborhood is typically a square or rectangle, but could be other shapes - Center of neighborhood is moved from pixel to pixel starting at the upper left hand corner of the Image - Operator T is applied at each location (x, y) to yield g(x, y) at that location Roger S. Gaborski 11 Intensity Transformations • Let the neighborhood be reduced to a size of 1 x 1 pixel • Now the transformation is only a function of the pixel itself. • This is commonly called an intensity transformation or gray level transformation function: s = T(r) where r is the intensity of f at (x, y) and s is the resulting intensity of g at (x, y) Roger S. Gaborski 12 Intensity Transformations • Assume the range of pixel intensity values is [0,1] • What can be accomplished with transformation T ? Roger S. Gaborski 13 Intensity Transformations >> R = rand([1 4]) R= 0.0272 0.7937 0.9992 0.1102 >> R2 = R .* R ( note .* and not simply * ) R2 = 0.0007 0.6299 0.9985 0.0122 (small numbers are much smaller) >> RSR = sqrt(R) RSR = 0.1649 0.8909 0.9996 0.3320 Roger S. Gaborski 14 R = rand(1, 4) R2 = R .* R RSR = sqrt(R) In this case the data is actually changed Not the only display as in previous lecture Roger S. Gaborski 15 Characteristics: • y = x2 : all pixels become darker • y = sqrt(x): all pixels become brighter • y = x: all pixels remain the same value Output (y) Input (x) Roger S. Gaborski 16 Intensity Transformations • Function imadjust – intensity transformation of gray scale images • g = imadjust( f, [low_in high_in], [low_out, high_out], gamma) – Input - output defined in [0,1] range: • [low_in high_in] [0 1] (min max) • [low_out high_out] [0 1] (min max) Roger S. Gaborski 17 Characteristics: • gamma >1 : all pixels become darker • gamma <1 : all pixels become brighter • gamma =1 : linear transform Gamma specifies the shape of the curve Brighter Output (gamma<1) Darker Output (gamma>1) Chapter 3 www.prenhall.com/gonzalezwoodseddins Roger S. Gaborski 18 >> I = imread('mammogram.tif'); >> figure, imshow(I) Roger S. Gaborski 19 >> I2 = imadjust(I, [.5 .75], [0 1]); >> figure, imshow(I2) Roger S. Gaborski 20 Reduce the amount of tissue Mapped to black: >> I3 = imadjust(I, [.25 .75], [0 1]); >> figure, imshow(I3) Roger S. Gaborski 21 .75 1.0 Output .50 I3 .25 I2 .25 .50 .75 1.0 Roger S. Gaborski Input 22 I4 = imadjust(I, [0, 1], [0, 1], 2) Gamma=2 Roger S. Gaborski 23 Negative of image: >> I4 = imadjust(I,[0 1], [1 0]); >> figure, imshow(I4) Or I4 = imcomplement(I); Roger S. Gaborski 24 Example, continued H = [.5 .5 .6 .7 .8 .2; .6 .3 .8 .9 .2 .4 ] H= 0.5000 0.5000 0.6000 0.7000 0.8000 0.2000 0.6000 0.3000 0.8000 0.9000 0.2000 0.4000 b = imadjust(H, [.3 .7],[.1 .9],1) Roger S. Gaborski 25 1.0 OUTPUT 0 .1 2 .3 .4 .5 .6 .7 .8 .9 Example 0 .1 .2 .3 .4 Roger.5 S. Gaborski .6 .7 .8 .9 1.0 26 INPUT 1.0 OUTPUT 0 .1 2 .3 .4 .5 .6 .7 .8 .9 Example:b=imadjust(H, [.3 .7],[.1 .9],1) 0 .1 .2 .3 .4 Roger.5 S. Gaborski .6 .7 .8 .9 1.0 27 INPUT 1.0 OUTPUT 0 .1 2 .3 .4 .5 .6 .7 .8 .9 Example:b=imadjust(H, [.3 .7],[.1 .9],1) 0 .1 .2 .3 .4 Roger.5 S. Gaborski .6 .7 .8 .9 1.0 28 INPUT Example, continued H = [.5 .5 .6 .7 .8 .2; .6 .3 .8 .9 .2 .4 ] H= 0.5000 0.5000 0.6000 0.7000 0.8000 0.2000 0.6000 0.3000 0.8000 0.9000 0.2000 0.4000 b=imadjust(H, [.3 .7],[.1 .9],1) b= 0.5000 0.5000 0.7000 0.9000 0.9000 0.1000 0.7000 0.1000 0.9000 0.9000 0.1000 0.3000 Roger S. Gaborski 29 Logarithmic Transformation • g = log(f ), where f is the input image – Issue: log(0) = -Inf – Any zeros in the input will be mapped to -Inf – Note: log(1) = 0 • g = log(1+f ) – This ensures that log(f ) is never mapped to -Inf – Similar to gamma transformation – Commonly used for dynamic range compression Roger S. Gaborski 30 Contrast Stretching Transformation • Creates an image with higher contrast than the input image: 1 s T (r ) m 1 ( )E r – r: intensities of input; – s: intensities of output; – m: threshold point (see graph) ; – E: controls slope. Roger S. Gaborski 31 Chapter 3 www.prenhall.com/gonzalezwoodseddins E controls the slope of the function Roger S. Gaborski 32 >> I = imread('mammogram.tif'); >> figure, subplot(2,2,1), imshow(I), title('I') >> E= 1; >> g = 1./(1+(m./(double(I)+eps)).^E); >> subplot(2,2,2), imshow(g),title('E=1') >> E= 3; >> g = 1./(1+(m./(double(I)+eps)).^E); >> subplot(2,2,3), imshow(g),title('E=3') >> E= 5; >> g = 1./(1+(m./(double(I)+eps)).^E); >> subplot(2,2,4), imshow(g),title('E=5') Roger S. Gaborski 33 1 s T (r ) m E 1 ( ) r Output(s) Input(r) Roger S. Gaborski 34 Roger S. Gaborski 35 Chapter 3 www.prenhall.com/gonzalezwoodseddins Input Output Roger S. Gaborski 36 Gray Image >> I = imread('Flags.jpg'); >> figure, imshow(I) % uint8 >> Im = im2double(I); % convert to double >> Igray = (Im(:,:,1)+Im(:,:,2)+Im(:,:,3))/3; >> figure, imshow(Igray) There is also the rgb2gray function that results in a slightly different image Roger S. Gaborski 37 rgb2gray help rgb2gray rgb2gray Convert RGB image or colormap to grayscale. rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance. I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I. Roger S. Gaborski 38
© Copyright 2024