920 likes | 1.01k Views
Lecture 3 Dr. Roger S. Gaborski. Introduction to Computer Vision. Quiz on Thursday Closed book, no notes Lectures 1-3 Textbook pp 1-64 pp80-86. Overview . Image displaying Image types Image adjustment Gamma t ransformation Logarithmic transformation
E N D
Lecture 3 Dr. Roger S. Gaborski Introduction to Computer Vision Roger S. Gaborski
Quiz on ThursdayClosed book, no notesLectures 1-3Textbook pp 1-64 pp80-86 Roger S. Gaborski
Overview • Image displaying • Image types • Image adjustment • Gamma transformation • Logarithmic transformation • Component segmentation • Histogram distribution Roger S. Gaborski
A Few Typical Operationswith Images >> ls *jpg OrangeFlower.jpgPatternOne.jpg >> I = imread('OrangeFlower.jpg'); >> whos I Name Size Bytes Class Attributes I 1880x2816x3 15882240 uint8 Roger S. Gaborski
What are maximum and minimum pixel values of I? >> mx = max(I(:)) mx = 255 >> mn = min(I(:)) mn = 0 Roger S. 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. Roger S. Gaborski
figure, imshow(I,'InitialMagnification' ,'fit') Roger S. 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. Roger S. Gaborski
im = uint8([0 50 100; 100 125 200; 200 250 275]) Im is of type uint8. What values are contained in im ? Roger S. Gaborski
im = uint8([0 50 100; 100 125 200; 200 250 275]) Im is of type uint8. What values are contained in im ? >> im im = 0 50 100 100 125 200 200 250 255 Roger S. Gaborski
Displaying Images >> figure, imshow(im, 'InitialMagnification' ,'fit') >> title('im') Roger S. 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 0.6, or 0.3 and 0.9 Roger S. Gaborski
Describe the displayed image A >> A = [.14 .15 ; .16 .17] A = 0.1400 0.1500 0.1600 0.1700 >> figure, imshow(A, 'InitialMagnification' ,'fit') Roger S. Gaborski
WHY? Roger S. Gaborski
figure, imshow(A, [],'InitialMagnification' ,'fit') The data in A didn’t change, only the display Roger S. Gaborski
mat2gray Change Actual Data Values: mat2gray Convert matrix to intensity image. I = mat2gray(A,[AMIN AMAX]) converts the matrix A to the intensity image I. The returned matrix I contains values in the range 0.0 (black) to 1.0 (full intensity or white). AMIN and AMAX are the values in A that correspond to 0.0 and 1.0 in I. Values less than AMIN become 0.0, and values greater than AMAX become 1.0. I = mat2gray(A) sets the values of AMIN and AMAX to the minimum and maximum values in A. Roger S. Gaborski
>> A A = 0.1400 0.1500 0.1600 0.1700 >> J = mat2gray(A) J = 0 0.3333 0.6667 1.0000 (Range is [0,1]) Roger S. Gaborski
B = 0 0.5000 5.0000 10.0000 >> J = mat2gray(B) J = 0 0.0500 0.5000 1.0000 (Range is [0,1]) Roger S. Gaborski
double and im2double >> Q=uint8([55, 100, 22]) Q = 55 100 22 >> whos Q Name Size Bytes Class Attributes Q 1x3 3 uint8 >> Qd = double(Q) What is the value of Qd? Roger S. Gaborski
>>> Qd = double(Q) Qd = 55 100 22 >> whos Q Qd Name Size Bytes Class Attributes Q 1x3 3 uint8 Qd 1x3 24 double >> Qid = im2double(Q) What is the value of Qid? Roger S. Gaborski
>> Qid = im2double(Q) Qid = 0.2157 0.3922 0.0863 >> whos Name Size Bytes Class Attributes Q 1x1 1 uint8 Qd 1x1 8 double Qid 1x1 8 double Roger S. Gaborski
>>> Qd = double(Q) Qd = 55 100 22 >> im2double(Qd) = ?????? Roger S. Gaborski
im2double(Qd) (Qd is already type double, no change) ans = 55 100 22 Roger S. 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 Roger S. Gaborski
Intensity Image >> Im = imread('Flag1.jpg'); >> whos I Name Size Bytes Class Attributes Im 320x240 76800 uint8 % Image is of class uint8, >> >> max(Im(:)) ans = 255 >> min(Im(:)) ans = 0 Range 0 to 255 (uint8) >> Im1 = im2double(Im); % Convert to class double >> max(Im1(:)) ans = 1 >> min(Im1(:)) ans = 0 Range now 0 to 1 (im2double) which is default format of images read from disk Roger S. Gaborski
Display images imshow(Im) imshow(Im) uint8 im2double(I) Roger S. Gaborski
How is display affected if the range of pixel values is changed? >> Im2 = Im1*2 +1; >> min(Im2(:)) ans = 1 >> max(Im2(:)) ans = 3 >> figure, imshow(Im2) Roger S. Gaborski
imshow(j) Reason: image Im2 is double class, which has the displaying range of [0, 1]. Range of image Im2: [1, 3] So all pixels are displayed as white. Roger S. Gaborski
figure, imshow(Im2, [ ]) imshow(Im2, [min(Im2(:)), max(Im2(:))]) imshow(Im2, [ ]) Roger S. 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 Roger S. Gaborski
Binary Image >> BW = imread('circles.png'); >> whos BW Name Size Bytes Class Attributes BW 256x256 65536 logical >> imshow(BW) Roger S. 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 Roger S. Gaborski
Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins Roger S. 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) Roger S. 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 Roger S. Gaborski
Chapter 2 – Fundamentals www.prenhall.com/gonzalezwoodseddins Roger S. 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 Roger S. 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) Roger S. 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? Roger S. 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? The brightness or intensity value at that spatial location Roger S. Gaborski
What if you inspect a neighborhood of pixel values? Roger S. Gaborski
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
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
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
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
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
Intensity Transformations • Assume the range of pixel intensity values is [0,1] • What can be accomplished with transformation T ? Roger S. 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 Roger S. Gaborski
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