03_Image-operations_updated
03_Image-operations_updated
Computer Vision
1
Outline
• Intensity profiles
• Image histograms
• Pixelwise operations
2
Reminder: What computers see
243 239 240 225 206 185 188 218 211 206 216 225
235 217 115 212 243 236 247 139 91 209 208 211
233 208 131 222 219 226 196 114 74 208 213 214
232 232 182 186 184 179 159 123 93 232 235 235
232 236 201 154 216 133 129 81 175 252 241 240
235 238 230 128 172 138 65 63 234 249 241 245
234 237 245 193 55 33 115 144 213 255 253 251
248 245 161 128 149 109 138 65 47 156 239 255
5
An image histogram is a vector where each entry is
the count (or statistical frequency) of the corresponding intensity value
100 100 100 100 100 110 110 110 110 110
100 100 100 100 100 110 110 110 110 110
100 100 100 100 100 110 110 110 110 110
100 100 100 100 100 110 110 110 110 110
100 100 100 100 100 110 110 110 110 110
100 100 100 100 100 110 110 110 110 110 40
100 100 100 100 100 110 110 110 110 110 35
80 80 80 80 80 80 80 80 200 200 30
80 80 80 80 80 80 80 80 200 200 25
80 80 80 80 80 80 80 80 200 200 20
15
10
0
0 20 40 60 80 100 120 140 160 180 200 220 240
6
Computing a histogram
. . .
img = cv2.imread('file.png', cv2.IMREAD_GRAYSCALE)
myHist = getHist(img, 256)
7
Noise and image smoothing (blur) cause the lobes in the histogram to spread;
below, Gaussian noise was added to pixel values
8
Histograms can reveal images that are
underexposed, properly exposed, or overexposed
9
Rembrandt van Rijn, Jacob Blessing the Children of Joseph
10
Rembrandt van Rijn, Jacob Blessing the Children of Joseph
11
Jan Vermeer, Young Woman with a Water Pitcher
12
Jan Vermeer, Young Woman with a Water Pitcher
13
PIXELWISE OPERATIONS
14
Pixelwise operations are common
(also called “point operations”)
Examples:
15
Histogram equalization is the adjusting of intensity values
in an image so that the new histogram is approximately flat
Something like
this is more
likely
16
The usual reason for histogram equalization
is to give the image a nicer appearance
(but doesn’t help with the operations that we’ll discuss)
17
Multi-image point operations produce a result by combining
pixels at the same locations in two (or more) source images:
18
Averaging two or more
registered images is a
common method for
reducing noise
19
Pixelwise subtraction will reveal differences between two images;
BUT noise is enhanced, and the registration must be excellent
20
Computing the pixelwise max or min of two images
can be used to reduce the effect of artifacts like glare,
or to find occasional defects (industrial inspection)
MAX
21
Many other pixelwise operations are possible
22
2-DIMENSIONAL FILTERS
(INTRODUCTION)
23
Image filtering
Common approach: for each pixel in an input image, compute one value at the
corresponding pixel location in an output image
– Often compute a function of that pixel’s local neighborhood
– Apply the same function at each pixel location
– Output image and input image are typically the same size
10 5 3 Some function
4 6 1 8
1 1 8
Local image data One output pixel
Original image
(some noise is visible)
• Let’s replace each pixel with the average of all the values in its neighborhood
• Assumptions:
– Expect pixels to be like their neighbors
– Expect noise processes to be independent from pixel to pixel
g[⋅ ,⋅ ]
1 1 1
1 1 1
1 1 1
Image filtering 1 1 1
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
?
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
?
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0 50
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0 90
0 0 0 90 0 90 90 90 0 0
0 0 0 90 90 90 90 90 0 0 50
0 0 0 0 0 0 0 0 0 0
0 0 90 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
g[⋅ ,⋅ ] = 1 1 1
1 1 1
1 1 1
Image filtering
f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10
0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20
0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30
0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30
0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
h[ m, n] = ∑ g[ k , l ] f [ m + k , n + l ]
Slide credit: S. Seitz k ,l
Box filter
g[⋅ ,⋅ ]
What does it do?
• Computes an output image in which each 1 1 1
original pixel has been replaced by the
average of its local neighborhood 1 1 1
1 1 1
• Achieves a smoothing effect
(reduces spatial changes in intensity)
Correlation filtering
0 0 0 0 0 0 0
?
0 0 0 0 0 0 0
a b c
0 0 0 0 0 0 0
d e f
0 0 0 1 0 0 0
g h i
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
G=H*F F
Notation for H
convolution
operator
Cross-correlation
• Shift Invariance:
same behavior regardless of
pixel location:
filter(shift(f)) = shift(filter(f))
More properties of linear filters
• Commutative: a * b = b * a
– Conceptually no difference between filter and signal
• Associative: a * (b * c) = (a * b) * c
– Often apply several filters one after another: (((a * b1) * b2) * b3)
– This is equivalent to applying one filter: a * (b1 * b2 * b3)
?
0 0 0
* 0 1 0 =
0 0 0
Original
0 0 0
* 0 1 0 =
0 0 0
Original Filtered
(no change)
- ?
0 0 0 1 1 1
*( 0 2 0 1 1 1 ) =
0 0 0 1 1 1
-
0 0 0 1 1 1
0 2 0 1 1 1
0 0 0 1 1 1
• Linear filtering
– Function is a weighted sum (or difference) of pixel values
10 5 3 0 0 0
4 6 1 0 0.5 0 8
1 1 8 0 1 0.5
• Many uses! Local image data Kernel Modified image data
– Enhance an image
• Denoise, smooth, increase contrast, etc.
– Extract information from an image
• Intensity edges, distinctive points, texture, etc.
– Detect patterns in an image
• Template matching
-1 0 1
-2 0 2
-1 0 1
Sobel
Vertical Edge
(absolute value)
Other examples
1 2 1
0 0 0
-1 -2 -1
Sobel
Horizontal Edge
(absolute value)
Coming soon
• Coordinate transformations
56
Summary
• Intensity profiles
• Image histograms
• Pixelwise operations
• Cross-correlation, convolution
57