Unformatted text preview: Image Transformations CGT 511
Image Transformations
Bedřich Beneš, Ph.D.
Purdue University
Department of Computer Graphics Technology • Color Transformations (pixels are not changing their positions)
• Geometric Transformations
(pixels can change positions, new can be added, some can be deleted) © Bedrich Benes Image Transformations Histogram • Color Transformations (pixels are not changing their positions) • image with intensity levels 0,1,…,L • histogram is a discrete function h(k), where h(k) gives # of pixels of intensity k
in the image
• vector of absolute frequencies of intensities • Geometric Transformations
(pixels can change positions, new can be added, some can be deleted) © Bedrich Benes © Bedrich Benes Histogram
Example: image resolution: 5 x 6
• Histogram: Histogram
void Histogram (char **image, int x, int y,
int *histogram)
{
int i,j; image: 0123456789
0 18 2 4 1 0 2 0 1 2
1 1 1 1 1 1 2 3 3 1 1 2 3 3 1 1
1 4
9 6
8 6
9 1
1 1 1 1 1 1 © Bedrich Benes Histogram
•
•
•
• for (i=0;i<255;i++) histogram[i]=0;
for (i=0;i<x;i++)
for (j=0;j<y;j++)
(j=0;j<
histogram[image[i][j]]++;
}
© Bedrich Benes Histogram Different images ‐> different histograms
RGB, CMY ‐ three
CMYK ‐ four (plus intensity)
Grayscale ‐ one In multidimensional cases, luminance is useful © Bedrich Benes © Bedrich Benes Histogram properties
1. Histogram properties 255 histogram(i) x. y 3. Histogram carries information about intensities of the image i 0 2. Different images can have equal histograms bright this is a bi‐modal histogram © Bedrich Benes dark high contrast
contrast bimodal © Bedrich Benes Image Classification Image Transformations
• Color Transformations (pixels are not changing their positions)
• Geometric Transformations
(pixels can change positions, new can be added, some can be deleted) low‐key
© Bedrich Benes high‐key average‐key high contrast
© Bedrich Benes Convolution Convolution • The most important operation with images
• So called convolution kernel (also called mask) is summed with an area of image, result is the value of a new pixel
• Also called sliding window
• The simples case an average © Bedrich Benes © Bedrich Benes Convolution Convolution • Continuous 1D convolution g ( x ) f ( x ) * h( x ) • Convolution kernel should sum to one f ( x)h( x t )dt h(t )dt 1 • Discrete 1D convolution
g[i ] f [i ] * h[i ] f [ k ]h[ k i ] • Discrete 2D convolution
g[i, j ] f [i, j ] * h[i, j ] f [k , l ]h[k i, l j ] © Bedrich Benes h[i] 1 i • Convolution kernel is typically symmetrical k k l © Bedrich Benes Convolution ‐ 1D discrete example Convolution ‐ 2D discrete example • f(x) f(x) all values = 1 h(x) 1 0 1 0 3 1 1 ‐4 1 2 3 3 1 0 1 0 4
9 6
8 6
9 1
1 1 1 1 1 1 0 0 0 0 0 0 ‐1 ‐3 ‐4 0 0 g(x) 1 3 1
1 • f(x)*g(x) 1 2 1 all five values = 0.2 1 1 • g(x) 1 4 0 1 0 2 ‐3 ‐5 0
0 ‐22 ‐7 ‐20 0
0 © Bedrich Benes 2 example for the yellow pixel:
1+1+3+2‐2*4 = 7 ‐ 8 = ‐1 0 0 0 0 © Bedrich Benes Noise Reduction Simple Averaging
1/9 1/9 1/9 • h(x,y)= 1/9 1/9 1/9 Noise Reduction Gaussian Filtering
• h(x,y)= 1/16 2/16 1/16
2/16 4/16 2/16 1/9 1/9 1/9
1/16 2/16 1/16 • Introduces heavy blur • The bigger the kernel, the heavier the blur © Bedrich Benes • Introduces heavy blur • The bigger the kernel, the heavier the blur © Bedrich Benes Noise Reduction – Median Filtering Image Sharpening • Is not convolution
• Take neighbors, sort them,take the median
Example: 10 12 13 ‐> sorted 10 10 10 10 10 11 12 13 19 19 11 10
10 10 10 •
1)
2)
• © Bedrich Benes Human perception is sensitive to edges
take the image and find the edges
add the edges to the image
G = F + c S
F ‐ input image, G ‐ output image, S ‐ edges of F
c ‐ coefficient of sharpening © Bedrich Benes Image Sharpening Image Sharpening • What is an edge? Gradient
is generalization of derivative step
ramp roof (tent) f ( x, y ) f ( x, y ) f ( x , y ) x , y line Is the direction of maximum increase of f(x,y)
this is it's size (number) is the rate of increase
s(x,y) Easy for humans, hard for an automatic process
© Bedrich Benes f ( x, y ) f ( x, y ) f ( x, y ) x y 2 © Bedrich Benes 2 Edge Detection – Robert’s operator
s(i,j) = f(i,j) ‐ f(i+1,j+1) + f(i ‐1,j) ‐ f(i,j‐1) i+1
• s(i,j) =
+ i+1,j
j+1
i,j i,j+1 • very sensitive to noise
• can be computed very fast
• it is NOT convolution
© Bedrich Benes Edge Detection – Sobel’s operator Edge Detection – Sobel’s operator 1 0 1
h(i, j ) 2 0 2 1 0 1 2 1 0 h(i, j ) 1 0 1 0
1 2 1 2 1
h(i, j ) 0
0
0 1
2
1 Properties
• it is convolution
• dependent on the direction (9 variants)
• thick edges
© Bedrich Benes Edge Detection ‐Laplace’s operator
0 1 0 h(i, j ) 1 4 1 0 1 0 f( x ) f(x) Properties:
x
• it is convolution
• approximates second derivative • doubles edges
2
2 f ( x, y ) f ( x, y ) 2 • in fact it is: f ( x, y ) © Bedrich Benes © Bedrich Benes x y Edge Detection ‐Laplace’s operator Image Sharpening Hint:
Do not use image sharpening repeatedly...
© Bedrich Benes Painting by numbers © Bedrich Benes Painting by numbers Impressionism
• second half of the 19th century
• image is dine by brush strokes of limited amount of colors
• the definitive color rises in the human eye
Pointillism • the brush is only put and not stroked.
© Bedrich Benes © Bedrich Benes Painting by Numbers
• Input: image f ‐ photograph Output: image g ‐ empty sheet of paper
Palette: of few colors and a brush
1) Divide f into equal squares (e.g., 5x5 pixels)
2) Get average of the colors in every square
3) For every square do:
a) choose closest color in the palette ~ 10%
b) put the color stroke under given direction
b) (pointillism) fill the square by circles © Bedrich Benes Painting by Numbers © Bedrich Benes Non‐Photorealistic Rendering Geometric Transformations • NPR – anything that displays 3D objects non‐
realistically
• Includes art, painting, drawing, sketching, • Is helpful in visualizations e.g., displaying medical data as sketches
• Includes cartoon‐like rendering •
•
•
• © Bedrich Benes How can we zoom an image [1.2,0.7]x?
Continuous image ‐ easily.
Discrete image ‐ hardly
1*1.2 = 1.2 we get non‐integer coordinates! © Bedrich Benes Geometric Transformations Geometric Transformations Discrete images are transformed by resampling
1) reconstruct the continuous original of the function
2) transform it
3) sample it again • Transformation and Sampling is easy
• How do we reconstruct?
• We need to find a continuous representation of a discrete image
• Is it possible?
• Few known points
• Convolution is the solution © Bedrich Benes © Bedrich Benes Reconstruction Nearest Neighbor Interpolation • Problem – what should be between samples? • Sample & hold
• Resamples with the closest value
• Fast, bad results (especially for text) © Bedrich Benes © Bedrich Benes Nearest Neighbor Linear Interpolation
• Linearly interpolates between values
• Good and fast results
• Blurs © Bedrich Benes Bilinear Interpolation
•
•
•
•
• © Bedrich Benes Bilinear In 2D we need to interpolate 3x
Linear interpolation is separable
Linearly interpolate AB‐>P
Linearly interpolate CD‐>R
Linearly interpolate PR‐>Q original
© Bedrich Benes © Bedrich Benes bilinear nearest neighbor Higher order interpolation Reconstruction and Convolution • Approximates the values by a higher order function • Usually preserves edges
• May be slow • Discrete f(x) • Continuous h(x) • Continuous h(x)*f(x)
© Bedrich Benes © Bedrich Benes The Box Filter
1 /(2r 1) r i r
hbox [i ] 0 otherwise 1 /( 2r ) r x r
hbox ( x) 0 otherwise The Tent Filter
1/(2r+1)
‐r r 1/(2r)
‐r 1  x   x  1
htent ( x) r 0 otherwise ‐r r • The filter is C0 continuous – no jumps r The filter is C0 continuous – no jumps
© Bedrich Benes 1/(2r) © Bedrich Benes Gaussian Filter
hGauss ( x) 1 x2 / 2
e
2 B‐Spline Cubic Filter 3(1  x ) 3 3(1  x ) 2 3(1  x ) 1 1 x 1
1
hB spline ( x) (2  x ) 3
1  x  2
6
0
otherwise • Does not have finite support
• Good sampling, expensive to calculate © Bedrich Benes © Bedrich Benes Filter properties Summary • Can be interpreted as weights that are assigned to each sample
• Filter can be interpolating
or approximating
• Soma can have overshoot
good for enhancing edges
• Separability – 2D can be done as multiple runs of 1D • continuous and discrete image © Bedrich Benes • digitalization ‐ sampling and quantization
• raster and vector image, rasterization, OCR © Bedrich Benes Readings
Rafael Gonzales, Richard Woods, Digital Image Processing, Addison Wesley Publishing, 1993, pages 307 ‐> Peter Shirley et al, Fundamentals of Computer Graphics 2nd edition, pp 71‐118 © Bedrich Benes ...
View
Full Document
 Fall '08
 Mohler,J
 Histogram, Bedrich Benes

Click to edit the document details