720 likes | 815 Views
Introduction to Computer Vision. Lecture 3 Dr. Roger S. Gaborski. Quiz – Thursday Read Chapter 1 in textbook, p1-34 Chapter 2, p35-65 You are responsible for material in the textbook even if the material is not covered in lecture. Displaying Images [0, 255].
E N D
Introduction to Computer Vision Lecture 3 Dr. Roger S. Gaborski
Quiz – Thursday • Read Chapter 1 in textbook, p1-34 • Chapter 2, p35-65 • You are responsible for material in the textbook even if the material is not covered in lecture. RS Gaborski
Displaying Images [0, 255] • Consider we would like to display a gray level image that has a possible range of values 0-255 • When we display the image we can arrange for each gray level value to be displayed as a different light level on the display • Black would map to the gray level 0, white would map to the gray level 255. • Gray level values between 0 and 255 would map to shades of gray. RS Gaborski
RECALL: Displaying Images [0,1] • The gray level of images can also be represented by real value numbers between 0 and 1. • 0 represents pixels that are black, 1 represents pixels that are white. • Values between 0 and 1 represent gray level values. RS Gaborski
Range of Gray Level Values • The maximum range of values is [0,1] or [0,255] (for 8 bit images) • It is possible for images to use the maximum range of gray level values, or some subset • An image may only contain values between 0 and .6, or .3 and .9 RS Gaborski
Image Types • Intensity images • When elements are class uint8 or uint16 they have integer values in the range [0 255] or [0 65535] • When elements are class double values are floating point numbers. Values are scaled in the range [0 1] by convention • Pixels with value 0.0 are displayed as black • Pixels with value 1.0 are displayed as white • Binary images • RGB images • Indexed images RS Gaborski
Intensity Image >> I = imread('Flag1.jpg'); >> whos I Name Size Bytes Class Attributes I 320x240 76800 uint8 Image is of class uint8 >> >> max(I(:)) ans = 255 >> min(I(:)) ans = 0 Range 0 to 255 >> i = im2double(I); Convert to class double >> max(i(:)) ans = 1 >> min(i(:)) ans = 0 Range now 0 to 1 RS Gaborski
Display image figure, imshow(i) RS Gaborski
How is display affected if the range of pixel values is changed >> j = i*2 +1; >> min(j(:)) ans = 1 >> max(j(:)) ans = 3 >> figure, imshow(j) RS Gaborski
imshow(j) RS Gaborski
figure, imshow(j) RS Gaborski
Image Types • Intensity images • Binary images • A logical array of 0s and 1s • An array of 0s and 1s that are of type uint8 is NOT a binary image • If A is a numeric array of 0s and 1s can create a logical array B using statement: B = logical(A) (all non zero values converted to 1s, entries with value 0 converted to logical 0s • RGB images • Indexed images RS Gaborski
Binary Image >> BW = imread('circles.png'); >> whos BW Name Size Bytes Class Attributes BW 256x256 65536 logical >> imshow(BW) RS Gaborski
Image Types • Intensity images • Binary images • RGB images • RGB color image is an MxNx3 array of color pixels • Each pixel is a triplet corresponds to the red, green and blue components at a specific spatial location • Can be interpreted as 3 planes of gray scale images fed into red, green and blue inputs of a color monitor • Class double, range of values [0,1] • Class uint8 or uint16 ranges are [0 255], [0 65535] • Indexed images RS Gaborski
Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins RS Gaborski
Image Types • Intensity images • Binary images • RGB images • Indexed images • Two components: data matrix of integers, X, and a color map matrix, map • Map matrix is an mx3 array of class double floating point numbers in the range [0,1] • m is the number of colors defined for the image • Each row of m specifies the r,g and b components of a single color • Example: imshow(X,map) RS Gaborski
Image Types • Indexed images • Indexed images use a direct mapping of pixel intensities to color map values • Color of each pixel is determined by using the corresponding values of integer matrix X as a pointer into map • If X is class uint8 or uint16 then all components with value 0 point to first row of map, value of 1 point to second row RS Gaborski
Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins RS Gaborski
Image Enhancement • Brightness mapping • Contrast stretching/enhancement • Histogram modification • Noise Reduction • Mathematical Techniques • Convolution • Filtering • Edge and Line Detection and Extraction • Region Segmentation • Contour Extraction • Corner Detection • Higher Level Features RS Gaborski
Intensity Transformation and Spatial Transformation • Intensity – modify each pixel in the image independently of its neighbors • Spatial – modify a pixel as a function of its neighbors (spatial convolution) RS Gaborski
If you look at a pixel of an intensity (gray level image- Next Slide) in isolation what can you tell me about the image?
If you look at a pixel of an intensity (gray level image) in isolation what can you tell me about the image? The brightness or intensity value at that spatial location
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 RS Gaborski
Can we modify the intensity values to change the image (improve in some way) or extract information from the image (edges, shapes, etc.)? RS Gaborski
Intensity Transformation and 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 RS Gaborski
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 RS Gaborski
Intensity Transformations • Let the neighborhood be reduced to a size of 1 x 1pixel • 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) RS Gaborski
Intensity Transformations • Assume the range of pixel intensity values is [0,1] • What can be accomplished with transformation T? RS Gaborski
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 RS Gaborski
In this case the data is actually changed Not the display as in previous lecture RS Gaborski
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) RS Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins Gamma specifies the shape of the curve Brighter Output Image Darker Output Image RS Gaborski
>> I = imread('mammogram.tif'); >> figure, imshow(I) >> I2 = imadjust(I, [.5 .75], [0 1]); >> figure, imshow(I2) RS Gaborski
Reduce the amount of tissue Mapped to black: >> I3 = imadjust(I, [.25 .75], [0 1]); >> figure, imshow(I3) RS Gaborski
Output .25 .50 .75 1.0 I3 I2 .25 .50 .75 1.0 RS Gaborski
Gamma=2 RS Gaborski
Negative of image: >> I4 = imadjust(I,[0 1], [1 0]); >> figure, imshow(I4) Or I4 = imcomplement(I); RS Gaborski
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 RS Gaborski
Contrast Stretching Transformation • Compresses input values lower than m into a narrow range of dark levels • Compresses input values higher than m into a narrow range of light levels • Creates an image with higher contrast than the input image: • s = T(r) = 1 / ( 1+(m/r)E • r: intensities of input; s: intensities of output • m: threshold point (see graph) ; E: controls slope RS Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins E controls the slope of the function RS Gaborski
>>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') RS Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins Input Output RS Gaborski
Intensity image is simply a matrix of numbers We can summary this information by only retaining the distribution if gray level values: PARTIAL IMAGE INFO: 117 83 59 59 68 77 84 94 82 67 62 70 83 86 85 81 71 65 77 89 86 82 76 67 72 90 97 86 66 54 68 104 121 107 85 46 58 89 138 165 137 91 38 80 147 200 211 187 138 40 80 149 197 202 187 146 56 76 114 159 181 160 113 An image shows the spatial distribution of gray level values RS Gaborski
Image Histogram Plot of Pixel Count as a Function of Gray Level Value RS Gaborski
Histogram • Histogram consists of • Peaks- high concentration of gray level values • Valleys – low concentration • Flat regions RS Gaborski
Formally, Image Histograms • Histogram: • digital image • L possible intensity levels in range [0,G] • Defined: h(rk) = nk • Where rk is the kth intensity level in the interval [0,G] and nk is the number of pixels in the image whose level is rk . • G: uint8 255 uint16 65535 double 1.0 RS Gaborski
Notation • L levels in range [0, G] • For example: • 0, 1, 2, 3, 4, in this case G = 4, L=5 • Since we cannot have an index of zero, • In this example, index of: Index 1 maps to gray level 0 2 maps to 1 3 maps to 2 4 maps to 3 5 maps to 4 RS Gaborski