Download presentation
Presentation is loading. Please wait.
Published byDaniel Curtis Modified over 9 years ago
1
ELE 488 Fall 2006 Image Processing and Transmission 09-21-06 1.Generate and Display of Gray Scale images in Matlab 2.Histogram of Gray Scale Image 3.Point Operations: brightness, contrast, gamma – correction 9/21/06
2
A Gray Scale Image: an array of integers (quantization) columns rows Intensity value at pixel (2,7) j i Each pixel can be addressed by a row and column number. MATLAB indexes from 1 to N. (although sometimes convenient to index from 0 to N – 1) 0 (black) 255 (white) Quantization
3
Generate and Display Images in Matlab 256 x 256 MATLAB: J=0.5 * ones(256,256); imshow(J) or image(J * 256) MATLAB: vones = ones(256,1); ramp=[0:1:255]/256; J=vones * ramp ’ ; imshow(J) Separable if J(i,j) = f(i) g(j) j i
4
Separable Images Special 2-D functions (i.e. images): In matrix notation, J is the outer product of vectors f and g: = * (column x row)
5
More Examples MATLAB: csig=cos(ramp * 4 * pi); J=csig’ * ramp; 256 x 256 MATLAB: J=cos(4*pi*ramp)*cos(4*pi*ramp)’; To use imshow, need to scale J so that 0 ≤ J ≤ 1.
6
2-D sinc function N=100; K=2; % how many cycles x=(-N:1:N)/N; x=(K*2*pi*x)’; f=sin(x)./x; f(N+1)=1; J = f * f’ ; % Normalize to 0,1 maxJ=max(max(J)); minJ=min(min(J)); J=(J-minJ)/(maxJ-minJ); figure(1);imshow(J); figure(2);mesh(x,x,J);
7
Load Image and Store Image in MATLAB 480 x 480 meanv = 104.0884 maxv = 219 minv = 0 m=480 n=480 A=imread(‘monkey’,’bmp’); or A=imread(‘monkey.bmp’); imshow(A); maxv=max(max(A)); minv=min(min(A)); meanv=mean2(A); [m n]=size(A);. (processing A to get B) imwrite(B,’mymonkey’,’bmp’); or imwrite(B, ‘mymonkey.bmp’);
8
Conversion uint8 double float in MATLAB B=im2double(A); mean2(B) ans=0.4082 max(max(B)) ans=0.8588 min(min(B)) ans=0 uint8 format: each pixel value is 1 byte unsigned integer, 0 to 255 double float format: each pixel value is a floating point number between 0 and 1. Float format is more convenient for mathematical operations, but may not be practical for final implementation
9
Luminance Histogram Represents the relative frequency of occurrence of the various gray levels in the image –For each gray level, count the # of pixels having that level –Can group nearby levels to form a big bin & count #pixels in it Pixels in image J take values from a set V=[0,…,L-1], e.g. L=256 Let k j be the number of pixels taking value j k j as a function of j is the image histogram of image J UMCP ENEE631 Slides (created by M.Wu © 2001/2004) j kjkj
10
Histogram in MATLAB 480 x 480 = 230,400 pixels MATLAB: imhist(A); % default 256 bins % binned with 4 equal bins: imhist(A,4);
11
Why Interested in Image Histograms Histogram shows distribution of pixel intensities - indicates dynamic range and can guide adjustment of image values. Normalized histogram can be interpreted as the probability that a randomly selected pixel takes a given value (or lies within a range of values). “Unbalanced” histogram doesn’t fully utilize the dynamic range Low contrast image ~ histogram concentrating in a narrow range Under-exposed image ~ histogram concentrating on the dark side Over-exposed image ~ histogram concentrating on the bright side Balanced histogram gives more pleasant look and reveals rich content Two images having similar histograms may be similar images. Images not having similar histograms are not similar. Applications in image/video classification, segmentation,...
12
UMCP ENEE631 Slides (created by M.Wu © 2004) Example: Balanced and Unbalanced Histograms Figure is from slides at Gonzalez/ Woods DIP book website (Chapter 3)
13
Point Operations / Intensity Transform Basic idea –“Zero memory” operation u each output only depend on the input intensity at the point –Map a given gray or color level u to a new level v, i.e. v = h ( u ) –Doesn’t bring in new info. –But can improve visual appearance or make features easier to detect Given a function h(x) and an image, denote the value of the (m,n)-th pixel by A(m,n). A point operation changes A(m,n) to B(m,n) according to B(m,n) = h ( A(m,n) ) independent of neighboring pixels. input gray level u output gray level v UMCP ENEE631 Slides (created by M.Wu © 2001/2004)
14
Contrast Stretching for Low-Contrast Images Stretch the over-concentrated graylevels in histogram via a nonlinear mapping –Piece-wise linear stretching function –Assign slopes of the stretching region to be greater than 1 UMCP ENEE631 Slides (created by M.Wu © 2001) expandcompress dynamic range
15
Contrast Stretching: Example original stretched UMCP ENEE631 Slides (created by M.Wu © 2001)
16
Point Operation: Scaling, h(x) = a*x A=imread(‘monkey’,’bmp’); A=im2double(A); imshow(A); imhist(A); a=max(max(A)); B=(1/a)*A; imshow(B); imhist(B); a<1 a>1
17
Point Operation: h(x) = a*x+b Point Operation: h(x) = a*x+b a – contrast, b – brightness [1, 0][0.5, 0][0.5, 0.25]
18
Point operation: brightness adjustment b=0.1 b=0.2b=0.3b=0.4 b shifting histogram
19
Point operation: linear contrast adjustment a=1.2 a=0.8 a=1.0 original more contrastless contrast h(x) = max ( min ( a(x – m) + m, 1), 0 )
20
Clipping & Thresholding Clipping –Special case of contrast stretching –Useful for noise reduction when interested signal mostly lie in range [a,b] Thresholding –Special case of clipping with a = b = T –Useful for scanned binary images u documents, signatures, fingerprints input gray level u output gray level v a b o input gray level u output gray level v T o UMCP ENEE631 Slides (created by M.Wu © 2001)
21
Gamma Characteristics & Gamma Correction Non-linearity in CRT display –Voltage U vs. Displayed luminance L’ L’ ~ U where = 2.0 ~ 2.5 Use pre-processing to compensate -distortion –U ~ L 1/ –log(L) gives similar compensation curve to - correction, good for many applications –Camera may have L 1/ c capturing distortion with c = 1.0 – 1.7 Power-law transformations are also useful for general purpose contrast manipulation U L’ L’ = a U L U ~ logL ~ L 1/ UMCP ENEE631 Slides (created by M.Wu © 2001/2004)
22
Gamma Correction UMCP ENEE631 Slides (created by M.Wu © 2004) Gonzalez/ Woods DIP book no correction with correction
23
UMCP ENEE631 Slides (created by M.Wu © 2004) Typical Types of Gray-level Transformation Gonzalez/ Woods DIP book
24
Examples of Histogram Equalization ( From Matlab Image Toolbox Guide Fig.10-10 & 10-11 ) UMCP ENEE631 Slides (created by M.Wu © 2001)
25
Equalization Example (cont’d) original equalized UMCP ENEE631 Slides (created by M.Wu © 2001)
26
Quick Review of Random Variable
27
Histogram Equalization n pixel gray level image, n k pixels have luminance r k, 0≤ k ≤L–1. To find transformation T, s k = T(r k ), so that {s k } is ‘uniformly’ distributed Model input luminance r as random variable with pdf p r ( ), and output luminance s as random variable with pdf p s ( ), 0≤ r, s ≤1. Then p s (w) = p r (u) / T’(u) with w=T(u). p s (w) = 1 = p r (u) / T’(u), so p r (u) = T’(u), and T(w) = ∫ w p r (u) du. (cdf of u) Discrete Case: approximate s k =T(r k ) = ∫ r k p r (u)du by General Case: to find transform from r to z having specified pdf p z ( ). –Find G( ) from z to s, with p s (w) = 1, as above. So s=G(z), z=G –1 (s). –Find T( ) from r to uniform s, as above. –s = T(r), z=G –1 (s)=G –1 (T(r)). and, from r k to z k, so that 0
28
gray levelr c.d.f Prob(r≤ r k ) = F u (r r ) rkrk o 1 1 F r (r k ) gray level s c.d.f Prob(s<=s k ) = F s (s k ) sksk o 1 1 F s (s k ) For uniform s, s k =F s (s k ) Histogram Equalization
29
Histogram Equalization: A Mini-Example r k 0 1 2 3 4 5 6 7 (L=8) p(r k ) 0.1 0.2 0.4 0.15 0.1 0.05 0 0 Σp=s k 0.1 0.3 0.7 0.85 0.95 1.0 1.0 1.0 0 [1.5] [4.7] [5.8] [6.6] 7 7 7 s k q 0 2 5 6 7 7 7 7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.