02 Image Enhancement in The Spatial Domain (Chapter 03)
02 Image Enhancement in The Spatial Domain (Chapter 03)
1 2 2 2 3 5 4 4 -2
-1 4
2 1 3 3 9
-1 -2
2 2 1 2
1 3 2 2
f f*h 8
Convolution Example – Step6
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h 1 3 2 2
2 2 2 3
5 4 4 -2
-2
2 2
1 3 3
9 6
2
-2 2
-2 1 2
1 3 2 2
f
f*h 9
Image Enhancement in the Spatial Domain
These two are called many names; the
Averaging/Smoothing/Blurring Filters
Extra:
Aside from the local-favoring
benefit of the filter to the right,
it is also better because it uses
multiples of two, and this is a
lot easier for the CPU to do,
cause all it needs to do is shift
left or right when doing
multiplication or division,
where the weights will need
multiplications by 2 and their
Gaussian divisor will need divisions by 2.
- Why should we divide by the sum of the weights (i.e., make the result sum to 1)? Because if I have an all 1s
window, the resulting pixel should also be 1. Otherwise, the filter would be manipulating the picture wrongly.
For example, average grade of three students who got 60 can't end up being something other than 60... lol.
- The filter to the right focuses more on the pixel that we're convolving at, in larger size filters this is more
10
effective, and the general reason is to favor the effect of local/nearby pixels since farther pixels are most
likely unrelated and would thus leave a stronger blur that feels much more different than the image.
Here's a test on a sample synthetic data. Synthetic data has the advantage of us including
as many corner cases as possible in one scenario, but has the inherent disadvantage of not
really being a correct simulation of real-life data that we should actually be testing against.
12
Image Enhancement in the Spatial Domain
13
Discuss what happens if you multiply (c) by (a). The result is that the bigger stars or galaxies will
stay in the picture while the rest will disappear. So, Avg. --> Threshold --> Multiply == Eliminate.
Important: The gray-scale range is 0...255
Random: If I tell you I have a q*q white block, this means
that it is totally surrounded by black blocks, because if it's
not, then I'm lying about it being q*q... (if there's a layer
Problem 3.22 around it of white, then it'd be (q+1)*(q+1), not q*q)
- Another approach of solving it is: Let the filter size be S (i.e., S*S pixels). The
result of one pixel would be 255*q*q / S*S. Let that = 255*1/10.
Then S = q*sqrt(10). Take its ceil to the nearest odd value, ggwpez
Example: T
00011111000
00000100000
00000000000
Problem 3.20 00000100000
(b) After bridging the gaps, it is desired to threshold the image in order to
convert it back to binary form. For your answer in (a), what is the
minimum value of the threshold required to accomplish this, without
causing the segments to break up again? Again going with that worst case, if I had a gap of 3,
then applying the filter on the center pixel means there
15
are only 2 foreground pixels and the remaining 5x5
pixels are all empty (three of them gaps, the rest
Important: The gray-scale range is 0...255 backgound), and so just less than 2(255)/25 should be
If not mentioned, make sure to assume it! the threshold, anything below it is not an averaged-gap.
So far the filters we saw are:
1. Averaging/Smoothing/Blur
2. Statistical (Median/Max/Min)
Order‐Statistics Filters
Median Filter
Maximum Filter
Minimum Filter
16
Order‐Statistics Filters
- Why does it work? Because in the normal image, the probability of having a max-wight or a max-black as part of the image itself (the salt and 17
pepper) is not that high, so when you do median filter it puts these very large/small values at either end of the range, thus eliminating them.
- When would it fail? If the number of salt/pepper noise pixels covers ceil( n^2 ) or more (where n = filter size), then one of them will surely be
the median. Note however that they have to be of the same type (i.e., ceil(n^2) of salt or ceil(n^2) of pepper)) for this condition to hold.
Remember, in averaging filter we add stuff up - similar to integration. So far the filters we saw are:
Hence in sharpening, we do differentiation - take differences! 1. Averaging/Smoothing/Blur
2. Statistical (Median/Max/Min)
3. Sharpening
Sharpening Spatial Filters The opposite of averaging/smoothing/blurring
Sharpening Spatial Filters a picture with no transitions at all (all smooth), the result
should be an empty image - no "edges" of transitions.
20
Since the operations are linear, we can do
sharpening in one step instead of these two:
Step 1: Use identity filter
Sharpening Spatial Filters Step 2: Use sharpen filter and add on top of
identity filter's result.
Merge the steps: Add the two filters!
21
Image Enhancement in the Spatial Domain
And this would
be the result:
24
(a) is original. (b) is Laplace filter of (a), made into 0 to 255 range by dividing and taking absolute value.
(c) is Laplace filter of (a), made into 0 to 255 range by dividing and adding. It now shows edges directions!
22
Problem 3.23
Extra: The statistical filters are non-linear, they don't work with the same idea of 23
25
This is a random example filter;
it shifts images to the right 1px.
Image Enhancement in the Spatial Domain
m is the hyper-parameter here
Identity: In = Out
Negative: Swaps black w/ white
Inverse log: As you can see, it
takes a large region of the input
and maps it into a small region
of the output's dark part, hence
the output is darkened input
nth power: Same, but weaker
nth root: Opposite of nth power 27
Lighten
Output = Const. * Input Gamma
28
Gamma Correction
29
Gamma Correction
30
So far we've used global filter techniques. This is bad. Local processing provides much more
robust and practical results, global is very rarely expected to give good practical results.
Contrast Stretching
This filter takes the input region
from 3L/8 to 5L/8 and expands it
onto L/8 to 7L/8, i.e., increasing the
contrast in that specific region of
the input image.
34