Image-sharpening spatial filters
- 1 Sharpening
- 2 Requirements of derivatives
- 3 Derivatives for digital images
- 4 Gray-level profile
- 5 Responses
- 6 Isotropy
- 7 Simpler notations for a subimage
- 8 First derivatives (gradient)
- 9 Exercise: Edge extraction
- 10 Second derivatives (Laplacian)
- 11 Exercise: Sharpening 1
- 12 Exercise: Sharpening 2
- 13 Exercise: Sharpening 3
- 14 Unsharp masking
- 15 High-boost filtering
- 16 Homework: Image sharpening filter
1 Sharpening
Smoothing/blurring is a process of “convolution” or “integration.”
Naturally, sharpening is a process of “derivation.”
2 Requirements of derivatives
First-order derivatives
- 0 in flat segments
- nonzero at the onset or end of a gray-level change
- nonzero along ramps
Second-order derivatives
- 0 in flat segments $\because \frac{\partial f}{\partial x}=0$
- nonzero at the onset or end of a gray-level change $\because \frac{\partial f}{\partial x}$ changes
- 0 along ramps of a constant slope $\because \frac{\partial f}{\partial x}$ is constant
$\partial x=1$
3 Derivatives for digital images
\[\frac{\partial f}{\partial x}=f(x+1)-f(x)\]
\[\begin{split} \frac{\partial^2 f}{\partial x^2}&=\frac{\partial}{\partial x}f(x)-\frac{\partial}{\partial x}f(x-1)\\ &=f(x+1)+f(x-1)-2f(x) \end{split}\]
4 Gray-level profile
5 Responses
First derivatives
- Generally thicker edges
- Stronger response to steps
Second derivatives
- Stronger response to fine details
- Double responses to steps
6 Isotropy
We are interested in “isotropic” filters, which are rotation-invariant.
That is, Rotate(Filter(Image)) = Filter(Rotate(Image)).
7 Simpler notations for a subimage
8 First derivatives (gradient)
The gradient $\mathbf{\nabla f}$ is a vector. \[\mathbf{\nabla f}= \begin{bmatrix} G_x\\ G_y \end{bmatrix} =\begin{bmatrix} \frac{\partial f}{\partial x}\\ \frac{\partial f}{\partial y} \end{bmatrix}\]
We use the magnitude of the gradient in digital image processing. \[\begin{split} \nabla f=\left|\mathbf{\nabla f}\right| &=\left[G_x^2+G_y^2\right]^{1/2}\\ &=\left[\left(\frac{\partial f}{\partial x}\right)^2+\left(\frac{\partial f}{\partial y}\right)^2\right]^{1/2} \end{split}\]
However, its computation for individual pixels is computationally expensive, so it is approximated as: \[\nabla f\approx|G_x|+|G_y|\]
8.1 Simplest approximation
\[G_x=z_8-z_5\] \[G_y=z_6-z_5\]
8.2 Roberts cross-gradient operators
\[G_x=z_9-z_5\] \[G_y=z_8-z_6\]
8.3 Sobel operators
An extension of Roberts cross-gradient operators
\[\begin{split} G_x&=(z_7-z_1)+2(z_8-z_2)+(z_9-z_3)\\ &=(z_7+2z_8+z_9)-(z_1+2z_2+z_3) \end{split}\]
\[\begin{split} G_y&=(z_3-z_1)+2(z_6-z_4)+(z_9-z_7)\\ &=(z_3+2z_6+z_9)-(z_1+2z_4+z_7) \end{split}\]
\[\nabla f\approx|G_x|+|G_y|\]
Multiplier $2$ for giving more importance to the current pixel
8.4 Filters for Sobel operators
9 Exercise: Edge extraction
- First derivative using the Sobel filter
- Input: map.tif
- Output: first_deriv.tif
- Gray-level slice
- Input: first_deriv.tif
- Lower gray level: 200
- Upper gray level: 1334
- New gray level: 255
- Binary: Checked
- Output: edges.tif
- Raster calculator
Int("edges.tif")
- Output: int_edges.tif
- Thin
- Input: int_edges.tif
- Output: thin_edges.tif
- Shape for corners: Sharp
- Maximum thickness: 30 ($10\times\text{cell size}$)
- Raster to polyline
- Input: thin_edges.tif
- Output: edges.shp
10 Second derivatives (Laplacian)
\[\nabla^2 f=\frac{\partial^2 f}{\partial x^2}+\frac{\partial^2 f}{\partial y^2}\]
\[\frac{\partial^2 f}{\partial x^2}=z_8+z_2-2z_5\]
\[\frac{\partial^2 f}{\partial y^2}=z_6+z_4-2z_5\]
\[\nabla^2 f=z_2+z_4+z_6+z_8-4z_5\]
10.1 Filters for the Laplacian
10.2 Sharpening
\[g(x,y)=f(x,y)-\nabla^2 f(x,y)\]
11 Exercise: Sharpening 1
- Second derivative using the Laplacian filter
- Input: map.tif
- Output: second_deriv.tif
- Subtract
- Input 1: map.tif
- Input 2: second_deriv.tif
- Output: sharpened_manual.tif
What happened?
Why?
12 Exercise: Sharpening 2
- Rescale gray levels
- Input: second_deriv.tif
- Lower gray level: -2040
- Upper gray level: 2040
- Output: rescaled_second_deriv.tif
- Subtract
- Input 1: map.tif
- Input 2: rescaled_second_deriv.tif
- Output: sharpened_better_manual.tif
13 Exercise: Sharpening 3
- Raster calculator
"map.tif" - "second_deriv.tif" / 16
- Output: sharpened_better_manual_2.tif
14 Unsharp masking
\[f_\text{s}(x,y)=f(x,y)-\bar{f}(x,y)\] where $\bar{f}(x,y)$ is a blurred $f(x,y)$
15 High-boost filtering
A generalized unsharp masking \[\begin{split} f_\text{hb}(x,y)&=A\cdot f(x,y)-\bar{f}(x,y)\\ &=(A-1)f(x,y)+f(x,y)-\bar{f}(x,y)\\ &=(A-1)f(x,y)+f_\text{s}(x,y) \end{split}\]
If we use the Laplacian sharpening for $f_\text{s}(x,y)$,
\[\begin{split} f_\text{hb}(x,y)&=(A-1)f(x,y)+f_\text{s}(x,y)\\ &=(A-1)f(x,y)+f(x,y)-\nabla^2 f(x,y)\\ &=A\cdot f(x,y)-\nabla^2 f(x,y). \end{split}\]
When $A=1$, $f_\text{hb}(x,y)$ is the Laplacian sharpening.
16 Homework: Image sharpening filter
Develop a 3-by-3 filter that can sharpen the input image in one pass. The output image need not be gray-level rescaled. In other words, the range of its pixel value doesn’t have to be between 0 and 255. Fill this blank filter with your nine coefficients.
Hints
- This one-pass filter is a combination of the diagonal Laplacian filter and exercise sharpening 3.
- Think about the identity and diagonal Laplacian filters.
- You can only run the Convolute tool once to sharpen the image. Again, don’t worry about its output range.
- Basically, you need to create a parameter value for “Filter mask values separated by a space” in the Convolute tool. That is nine numbers separated by a space.
- Coefficients are all real numbers. Use up to four significant figures.