260 likes | 375 Views
Manipulating contrast/point operations. Examples of point operations:. Threshold (demo) Invert (demo) Out[ x,y ] = max – In[ x,y ] RGB gray conversion Gamma correction Other methods histogram equalization color to gray scaling. Gray to binary. Thresholding G B
E N D
Examples of point operations: • Threshold (demo) • Invert (demo) Out[x,y] = max – In[x,y] • RGB gray conversion • Gamma correction • Other methods • histogram equalization • color to gray • scaling
Gray to binary • Thresholding • G B const int t=200; if (G[r][c]>t) B[r][c]=1; else B[r][c]=0; How do we choose t? • Interactively • Automatically
Histogram equalization • For many images we observe that it only uses a few different gray values. • Often these gray values are close together.
Histogram equalization • Histogram equalization goals: • Output image should use all gray values. • Output image has same number of pixels of each gray value. • Which distribution is then preferred? (normal or uniform) • (While maintaining the relationship (order) among gray values. - George’s rule.)
Histogram equalization from http://en.wikipedia.org/wiki/Histogram_equalization
Histoeq example(from http://www.cs.utah.edu/~jfishbau/improc/project2/images/crowd_hist_compare.png)
Histogram equalization • Histogram equalization attempts to remap the input gray values to output gray values s.t. the histogram of the output achieves goals 1 and 2 (and 3) as best as possible.
Histoeq example(from http://web2.clarkson.edu/class/image_process/qa1/Histogram%20Equalization%20Example_files/img92.gif)
Histogram • Step 1: Estimate probability of a given gray value in an image. • h(g) = count of pixels w/ gray value equal to g. • histogram • p(g) = h(g) / (w*h) • w*h = # of pixels in entire image • Demo histogram.
Histogram equalization • Step 2: Estimate c.d.f. (cumulative distribution function).
Histogram equalization • Step 3: Use c.d.f. to map an input gray value g to “equalized” gray value, g’. • Note: Since cdf(g) is in [0..1], we need to multiply by the max gray value so the result is in [0..max]. • Note: Calculate above only once for each gray value, save in a (lookup) table, and then let g’=lut[g].
Histogram equalization • Only gray eq discussed so far. • What about color? • Create 3 separate histograms for R, G, and B, and then equalize each individually (same as gray). • Better way is to convert RGB to color space with luminance (e.g., CIE XYZ, YIQ, YUV, HSL, or HSV), equalize luminance (same as gray), then convert back to RGB.
Histogram equalization algorithm • Do Exercise 5.2 for homework.
What about gray data that is less than 8 bits? • Linearly map input [0,K] to [0,255].
What about gray data that is less than 8 bits? • What if our minimum input value is something other than 0?
What about gray data that is more than 8 bits? • Linearly map input min to 0 and input max to 255. • But we then compress (lose) our dynamic range, i.e., lose details. • Map subranges of gray data to [0..255]. • A.K.A. window width and level.
from http://www.netterimages.com/images/vpv/000/000/061/61653-0550x0475.jpg
Window width and level • Map subranges of gray data to [0..255]. • A.K.A. window width and level.
Window width and level • Map subranges of gray data to [0..255]. • A.K.A. window width and level.
from https://www.imt.liu.se/people/dafor/visualization_files/image001.png
Standard conversion from rgb to gray • NTSC luminance int luminance = (int)(0.30*r + 0.59*g + 0.11*b + 0.5); if (luminance<0) luminance = 0; if (luminance>255) luminance = 255; http://www.tektronix.com/Measurement/cgi-bin/framed.pl?Document=/Measurement/App_Notes/NTSC_Video_Msmt/colorbars.html&FrameSet=television