820 likes | 955 Views
Lecture 3 Dr. Roger S. Gaborski. Introduction to Computer Vision. In Class Exercise Today – end of class. Homework. Homework #1 Assigned Due March 19th at 8am Orange Flower image available on course webpage
E N D
Lecture 3 Dr. Roger S. Gaborski Introduction to Computer Vision Roger S. Gaborski
In Class Exercise Today – end of class Roger S. Gaborski
Homework • Homework #1 Assigned • Due March 19th at 8am • Orange Flower image available on course webpage • Late homework – Emailed by 8am the day after it is due -25%. (In this case, by 8am March20th. ) 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 min and max values contained in im ? What is the ‘shape’ of variable 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 im is a 3x3 matrix Roger S. Gaborski
Displaying Images >> figure, imshow(im, 'InitialMagnification' ,'fit') >> title('im') What is contrast? 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 a subset of possible values • An image may only contain values between 0 and 0.6, or 0.3 and 0.9 • Is the contrast the same? How does the appearance differ? 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 >> A1 = mat2gray(A) A1 = 0 0.3333 0.6667 1.0000 (Range is [0,1]) Roger S. Gaborski
B = 0 0.5000 5.0000 10.0000 >> B1 = mat2gray(B) B1 = 0 0.0500 0.5000 1.0000 (Range is [0,1]) Roger S. Gaborski
C = -10.0000 0.5000 5.0000 10.0000 >> C1 = mat2gray(B) C1 = 0 0.5250 0.7500 1.0000 The original range is -10 to +10 mat2gray converts the range to 0 to +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('Flag.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 Image >> Flag= im2double(imread(‘flag.jpg’)); >> figure, imshow(Flag), title(‘flag’);
Extract a Region of the Image >> imRegion = imcrop(Flag); >> figure, imshow(imRegion), title('imRegion') >> size(imRegion) ans = 321 321 3
R, G, B planes >> imshow(imRegion(:, :, 1)), title(‘RED’); >> imshow(imRegion(:, :, 2)), title(‘GREEN’); >> imshow(imRegion(:, :, 3)), title(‘BLUE’);
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 independent 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