540 likes | 676 Views
Introduction to Computer Vision. Lecture 4 Dr. Roger S. Gaborski. First Homework will be posted on the course webpage on Friday The problem will be due Tuesday at 10am Submit your results to (no hardcopy): rsg.introcv@gmail.com Details of what to submit is on the homework assignment page.
E N D
Introduction to Computer Vision Lecture 4 Dr. Roger S. Gaborski
First Homework will be posted on the course webpage on Friday • The problem will be due Tuesday at 10am • Submit your results to (no hardcopy): rsg.introcv@gmail.com Details of what to submit is on the homework assignment page 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: 1 maps to 0 2 maps to 1 3 maps to 2 4 maps to 3 5 maps to 4 RS Gaborski
Normalized Histogram • Normalized histogram is obtained by dividing elements of h(rk) by the total number of pixels in the image (n): p(rk ) = h(rk) / n = nk /n for k = 1,2,..,L p(rk ) is an estimate of the probability of occurrence of intensity level rk RS 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 • p = imhist( f, b ) / numel(f) RS Gaborski
Gray Image >> I = imread('Flags.jpg'); >> figure, imshow(I) %uint8 >> Iint = mat2gray(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 RS Gaborski
rgb2gray First, convert to NTSC components: Y .299 .587 .114 R I = .596 -.274 -.322 G Q .211 -.523 .312 B Set I and Q components to zero, convert back to rgb: R 1.000 .956 .621 Y G = 1.000 -.272 -.647 I B 1.000 1.106 1.703 Q This will result in a gray image RS Gaborski
Color and Gray Scale Images RS Gaborski
Gray Scale Histogram RS Gaborski
Normalized Gray Scale Histogram >> p= imhist(Igray)/numel(Igray); >> figure, plot(p) RS Gaborski
Normalized Gray Scale Histogram 256 bins 32 bins imhist(Igray)/numel(Igray); imhist(Igray,32)/numel(Igray) RS 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 • .8 default RS 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 RS Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins RS Gaborski
Chapter 3 www.prenhall.com/gonzalezwoodseddins RS Gaborski
Korean Text %readKorean.m image = imread('Korean1.jpg'); Convert to grayscale image image1 figure, imshow(image1) Gray scale image RS Gaborski
Line Profile and Image1 Histogram Generate profile of text page at line 372 figure, plot(1:cols,image1(372,:)); RS Gaborski
A Quick Look Ahead • Threshold image to obtain 0/1 pixels • Detect skew and rotate image • Segment characters • Label individual components of characters • Identify characters RS Gaborski
Threshold • ImageThreshold = image>thresholdValue • Convert a double image with pixels in the range [0 1] to a binary image • Pixels have either a 0 or 1 value • The choice of thresholdValue in combination with quality of original image will determine binary image quality: • Broken characters • Filled in characters, such as, a, q, o, • Touching characters RS Gaborski
Threshold = .7 SKEW RS Gaborski
Image Rotation >> figure, imshow(imrotate(d,10)); RS Gaborski
Segmentation of Korean Characters RS Gaborski
Labeled Components of Korean Characters Input image Output image RS Gaborski
Color and Gray Scale ImagesRecall from Previous Slide RS Gaborski
Normalized Gray Scale Histogram >> p= imhist(Igray)/numel(Igray); >> figure, plot(p) probability Gray level values RS Gaborski
How could we transform the pixel values of an image so that they occupy the whole range of values between 0 and 255? RS 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?? RS Gaborski
CUMULATIVE DISTRIBUTION FUNCTION Histogram CDF RS Gaborski
Histogram Equalization • The histogram equalization transformation generates an image with equally likely intensity values • The intensity values in the output image cover the full range, [0 1] • The resulting image has higher dynamic range • Recall the values in the normalized histogram are approximately the probability of occurrence of those values • The histogram equalization transform is the cumulative distribution function (CDF) RS 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: sk = T( rk ) = pr(rj) = nj / n k k k = 1,2,…,L sk is intensity value of output rk is input value j=1 j=1 Sum of probability up to k value RS Gaborski
Histogram Equalization Example • g = histeq(f, nlev) where f is the original image and nlev number of intensity levels in output image RS Gaborski
INPUT RS Gaborski
Transformation x255 Output Gray Level Value Input Gray Level Value RS Gaborski