740 likes | 902 Views
Lecture 4 Dr. Roger S. Gaborski. Introduction to Computer Vision. HW#2 Due 02/13. In Class Exercise Review. 1. Given the following MATLAB code: >> image1 = rand([3]) image1 = 0.9500 0.6555 0.0318 0.7431 0.1712 0.2769 0.3922 0.7060 0.0462
E N D
Lecture 4 Dr. Roger S. Gaborski Introduction to Computer Vision Roger S. Gaborski
HW#2 Due 02/13 Roger S. Gaborski
In Class Exercise Review 1. Given the following MATLAB code: >> image1 = rand([3]) image1 = 0.9500 0.6555 0.0318 0.7431 0.1712 0.2769 0.3922 0.7060 0.0462 >> image2 = imadjust(image1, [ .1,.75],[.2, .6]) Carefully draw the transformation map specified by the imadjust statement. Label the x and y axis. Roger S. Gaborski
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
image1 = 0.9500 0.6555 0.0318 0.7431 0.1712 0.2769 0.3922 0.7060 0.0462 >> image2 = imadjust(image1, [ .1,.75],[.2, .6]) image2 = 0.6000 0.5418 0.2000 0.5958 0.2438 0.3089 0.3798 0.5729 0.2000 Roger S. Gaborski
Example 0 .1 2 .3 .4 .5 .6 .7 .8 .9 1.0 OUTPUT 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0 Roger S. Gaborski INPUT
image2 = imadjust(image1, [ .1,.75],[.2, .6],1) 0 .1 2 .3 .4 .5 .6 .7 .8 .9 1.0 OUTPUT 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0 Roger S. Gaborski INPUT
image2 = imadjust(image1, [ .1,.75],[.2, .6],1) 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0 OUTPUT 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1.0 Roger S. Gaborski INPUT
Gray Scale Ramp Image Minimum gray value = .01 Maximum gray value = 1.0 Roger S. Gaborski
Ramp Image image_ramp = zeros(100); for i = 1:100 image_ramp(:,i) = i*.01; end fprintf('minimum gray value = %d, \n', min(image_ramp(:))); fprintf('maximun gray value = %d, \n', max(image_ramp(:))); figure, plot(image_ramp(50,:)), xlabel('pixel position'), ylabel('pixel value') title('values') pause figure, imshow(image_ramp),title('ramp intensity image') pause Roger S. Gaborski
Map .01 to .5 and 1.0 to .75 Roger S. Gaborski
disp('Use imadjust to map to .50 to .75'); image1 = imadjust(image_ramp,[.01, 1.0],[.5, 0.75]); %map to .5 to .75 fprintf('minimum gray value = %d, \n', min(image1(:))); fprintf('maximun gray value = %d, \n', max(image1(:))); figure, plot(image1(50,:)), xlabel('pixel position'), ylabel('pixel value') title('values') axis([0,100,0,1]) Grid pause figure, imshow(image1, [0,1]); pause Roger S. Gaborski
Map .01 to .5 and 1.0 to .75 Roger S. Gaborski
Map values in range <=.25 to .35 and >=.50 to .65'); Roger S. Gaborski
Map values in range <=.25 to .35 and >=.50 to .65'); disp('Use imadjust to map values in range <=.25 to .35 and >=.50 to .65'); image2 = imadjust(image_ramp,[.25, .50],[.35, 0.65]); fprintf('minimum gray value = %d, \n', min(image2(:))); fprintf('maximun gray value = %d, \n', max(image2(:))); figure, plot(image2(50,:)), xlabel('pixel position'), ylabel('pixel value') title('values') axis([0,100,0,1]) grid pause figure, imshow(image2, [0,1]); Roger S. Gaborski
Map values in range <=.25 to .35 and >=.50 to .65'); Roger S. Gaborski
Contrast Stretching Transformation • Creates an image with higher contrast than the input image: • r: intensities of input; • s: intensities of output; • m: threshold point (see graph) ; • E: controls slope. Roger S. Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins E controls the slope of the function Roger S. Gaborski
Output(s) Input(r) Roger S. Gaborski
Introduction to Computer Vision Lecture 4 Dr. Roger S. 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 Roger S. Gaborski
Image Histogram Plot of Pixel Count as a Function of Gray Level Value Pixel Count Gray Level Value Roger S. Gaborski
Histogram • Histogram consists of • Peaks: high concentration of gray level values • Valleys: low concentration • Flat regions Roger S. 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 Roger S. 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 Roger S. Gaborski
Normalized Histogram • Normalized histogram is obtained by dividing elements of h(rk) by the total number of pixels in the image (n): fork = 1, 2,…, L p(rk) is an estimate of the probability of occurrence of intensity level rk Roger S. Gaborski
MATLAB Histogram • h = imhist( f, b ) • h is the histogram, h(rk) • f is the input image • b is the number of bins (default is 256) • Normalized histogram Roger S. Gaborski
Color and Gray Scale Images Roger S. Gaborski
Background: 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
Gray Scale Histogram Roger S. Gaborski
Plots • bar(horz, v, width) • v is row vector • points to be plotted • horz is a vector same dimension as v • increments of horizontal scale • omitted axis divided in units 0 to length(v) • width number in [0 1] • 1 bars touch • 0 vertical lines • 0.8 default Roger S. Gaborski
p= imhist(Igray)/numel(Igray); >> h1 = p(1:10:256); >> horz = (1:10:256); >> figure, bar(horz,h1) Review other examples in text and in MATLAB documentation Roger S. Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins Roger S. Gaborski
Color and Gray Scale ImagesRecall from Previous Slide Roger S. Gaborski
Gray Scale Histogram Roger S. Gaborski
Normalized Gray Scale Histogram >> p= imhist(Igray)/numel(Igray); >> figure, plot(p) Roger S. Gaborski
Normalized Gray Scale Histogram 256 bins 32 bins imhist(Igray)/numel(Igray); imhist(Igray,32)/numel(Igray) Roger S. Gaborski
Normalized Gray Scale Histogram >> p= imhist(Igray)/numel(Igray); >> figure, plot(p) probability Gray level values Roger S. Gaborski
Original Dark Light Roger S. Gaborski
Contract enhancement • How could we transform the pixel values of an image so that they occupy the whole range of values between 0 and 255? Roger S. Gaborski
Gray Scale Transformation • How could we transform the pixel values of an image so that they occupy the whole range of values between 0 and 255? • If they were uniformly distributed between 0 and x we could multiply all the gray level values by 255/x • BUT – what if they are not uniformly distributed?? Roger S. Gaborski
Cumulative Distribution Function Histogram CDF Roger S. Gaborski
Histogram Equalization(HE) • HE generates an image with equally likely intensity values • Transformation function: Cumulative Distribution Function (CDF) • The intensity values in the output image cover the full range, [0 1] • The resulting image has higher dynamic range • The values in the normalized histogram are approximately the probability of occurrence of those values Roger S. Gaborski
Histogram Equalization • Let pr(rj), j = 1, 2, … , L denote the histogram associated with intensity levels of a given image • Values in normalized histogram are approximately equal to the probability of occurrence of each intensity level in image • Equalization transformation is: k = 1,2,…,L sk is intensity value of output rk is input value Sum of probability up to k value Roger S. Gaborski
Histogram Equalization Example • g = histeq(f, nlev) where f is the original image and nlev number of intensity levels in output image Roger S. Gaborski
Original Image INPUT Roger S. Gaborski
Transformation x255 Output Gray Level Value Input Gray Level Value Roger S. Gaborski
Equalization of Original Image OUTPUT Roger S. Gaborski