Area/Mask Processing Methods: - What Is A Mask?
Area/Mask Processing Methods: - What Is A Mask?
(Trucco, Chapt 3)
- A pixel’s value is computed from its old value and the values of pixels in its vicinity.
- More costly operations than simple point processes, but more powerful.
• What is a Mask?
- The origins of symmetric masks are usually their center pixel position.
- For nonsymmetric masks, any pixel location may be chosen as the origin (depending
on the intended use).
1
1 1 1 1 2 1
1
1 1 1 2 4 2
1
1 1 1 1 2 1
1
• Applying Masks to Images (filtering)
- The application of a mask to an input image produces an output image of the same
size as the input.
Convolution
(1) For each pixel in the input image, the mask is conceptually placed on top of
the image with its origin lying on that pixel.
(2) The values of each input image pixel under the mask are multiplied by the
values of the corresponding mask weights.
(3) The results are summed together to yield a single output value that is placed
in the output image at the location of the pixel being processed on the input.
-2-
z1 z2 z3
z4 z5 z6 z5’ g(x,y) = T[f(x,y)]
z7 z8 z9 T
T operates on a
neighborhood of pixels
n/2 n/2
g(i, j) = Σ Σ h(k, l) f (i − k, j − l)
k=−n/2 l=−n/2
Cross Correlation
- Correlation translates the mask directly to the image without flipping it.
- If the mask is symmetric (i.e., the flipped mask is the same as the original one)
then the results of convolution and correlation are the same.
n/2 n/2
g(i, j) = Σ Σ h(k, l) f (i + k, j + l)
k=−n/2 l=−n/2
-4-
Non-linear filtering
- Linear filters have the property that the output is a linear combination of the
inputs.
- The sum of weights in the convolution mask affect the overall intensity of the result-
ing image.
- Many convolution masks have coefficients that sum to 1 (the convolved image will
have the same average intensity as the original one).
- Pixels with negative values may be generated using masks with negative weights.
- Negative values are mapped to the positive range through appropriate normalization.
• Practical problems
• Gaussian (linear filter) (from "Machine Vision" by Jain et al., Chapt 4 and Trucco Chapt 3)
−(x 2 + y 2 )
h(x, y) = exp[ ]
2 2
- The Gaussian’s mask weights fall off to (almost) zero at the mask’s edges.
- Gaussian smoothing can be implemented efficiently thanks to the fact that the
kernel is separable:
n/2 n/2
g(i, j) = Σ Σ
k=−n/2 l=−n/2
h(k, l) f (i − k, j − l) =
n/2 −k 2 n/2 −l 2
Σ exp[ 2 2 ] l=−n/2
k=−n/2
Σ exp[ 2 2 ] f (i − k, j − l)
-7-
Algorithm
To convolve an image I with a nxn 2D Gaussian mask G with =
g =
- As increases, the size of the mask must also increase if we are to sample the
Gaussian satisfactorily.
- Effective for removing "salt and pepper" noise (random occurences of black and
white pixels).
- Replace each pixel value by the median of the gray-levels in the neighborhood
of the pixels
Area or Mask Processing Methods
10 20 20
15 99 20 20 g(x,y) = T[f(x,y)]
20 25 20 T
T operates on a
neighborhood of pixels
10 20 20 15 99 20 20 15 20
sort
10 15 20 20 20 20 20 20 99
median
-9-
- It is used to emphasize the fine details of an image (has the opposite effect of
smoothing).
- When the mask is over an area of constant or slowly varying gray level, the result of
convolution will be close to zero.
- When gray level is varying rapidly within the neighborhood, the result of convolu-
tion will be a large number.
- Typically, such points form the border between different objects or scene parts (i.e.,
sharpening is a precursor step to edge detection).
1/9 (−10 − 80 − 80 −10 + 640 −80 −10 −80 −80) = 210/9 > 0
(there is variation in the gray−levels)
∂f
grad( f ) = ∂x
∂f
∂y
1 −1 −1 1
−1 1 1 −1
Prewitt masks
−1 −1 −1 −1 0 1
0 0 0 −1 0 1
1 1 1 −1 0 1
My Mx