Filtering Digital filters are used to blur and sharpen digital images. Filtering can be performed by: •
convolution with specifically designed
kernels (filter array) in the spatial domain • masking specific frequency regions in the frequency (Fourier) domain The following examples show both methods:
Image padding in Fourier domain filtering Images are typically padded before being transformed to the Fourier space, the
highpass filtered images below illustrate the consequences of different padding techniques: Notice that the highpass filter shows extra edges when zero padded compared to the repeated edge padding.
Filtering code examples MATLAB example for spatial domain highpass filtering. img=checkerboard(20); % generate checkerboard % ************************** SPATIAL DOMAIN *************************** klaplace=[0 -1 0; -1 5 -1; 0 -1 0]; % Laplacian filter kernel X=conv2(img,klaplace); % convolve test img with % 3x3 Laplacian kernel figure() imshow(X,[]) % show Laplacian filtered title('Laplacian Edge Detection')
Affine transformations Affine transformations enable basic image transformations including scale, rotate, translate, mirror and shear as is shown in the following examples:
Image denoising with mathematical morphology Mathematical morphology (MM) is a nonlinear image processing framework that analyzes shapes within images by probing local pixel neighborhoods using a small, predefined function called a
structuring element. In the context of
grayscale images, MM is especially useful for denoising through
dilation and
erosion—primitive operators that can be combined to build more complex filters. Suppose we have: • A discrete grayscale image: f = \begin{bmatrix} 45 & 50 & 65 \\ 40 & 60 & 55 \\ 25 & 15 & 5 \end{bmatrix}, \quad f : \Omega \rightarrow \mathbb{R}, \quad \Omega = \{0, 1, 2\}^2, • A structuring element: B = \begin{bmatrix} 1 & 2 & 1 \\ 2 & 1 & 1 \\ 1 & 0 & 3 \end{bmatrix}, \quad B : \mathcal{S} \rightarrow \mathbb{R}, \quad \mathcal{S} = \{-1, 0, 1\}^2. Here, \mathcal{S} defines the neighborhood of relative coordinates (m, n) over which local operations are computed. The values of B(m, n) bias the image during dilation and erosion. ; Dilation : Grayscale dilation is defined as: (f \oplus B)(i, j) = \max_{(m, n) \in \mathcal{S}} \Bigl\{ f(i+m, j+n) + B(m,n) \Bigr\}. :For example, the dilation at position is calculated as: \begin{aligned} (f \oplus B)(1,1) = \max\!\Bigl( &f(0,0)+B(-1,-1), &\;45+1;&\\ &f(1,0)+B( 0,-1), &\;50+2;&\\ &f(2,0)+B( 1,-1), &\;65+1;&\\ &f(0,1)+B(-1, 0), &\;40+2;&\\ &f(1,1)+B( 0, 0), &\;60+1;&\\ &f(2,1)+B( 1, 0), &\;55+1;&\\ &f(0,2)+B(-1, 1), &\;25+1;&\\ &f(1,2)+B( 0, 1), &\;15+0;&\\ &f(2,2)+B( 1, 1) &\;5+3 \Bigr) = 66. \end{aligned} ; Erosion : Grayscale erosion is defined as: (f \ominus B)(i,j) = \min_{(m,n) \in \mathcal{S}} \Bigl\{ f(i+m, j+n) - B(m,n) \Bigr\}. :For example, the erosion at position is calculated as: \begin{aligned} (f \ominus B)(1,1)= \min\!\Bigl( &f(0,0)-B(-1,-1), &\;45-1;&\\ &f(1,0)-B( 0,-1), &\;50-2;&\\ &f(2,0)-B( 1,-1), &\;65-1;&\\ &f(0,1)-B(-1, 0), &\;40-2;&\\ &f(1,1)-B( 0, 0), &\;60-1;&\\ &f(2,1)-B( 1, 0), &\;55-1;&\\ &f(0,2)-B(-1, 1), &\;25-1;&\\ &f(1,2)-B( 0, 1), &\;15-0;&\\ &f(2,2)-B( 1, 1) &\;5-3 \Bigr) =2. \end{aligned}
Results After applying dilation to f: \begin{bmatrix} 45 & 50 & 65 \\ 40 & 66 & 55 \\ 25 & 15 & 5 \end{bmatrix} After applying erosion to f: \begin{bmatrix} 45 & 50 & 65 \\ 40 & 2 & 55 \\ 25 & 15 & 5 \end{bmatrix}
Opening and Closing MM operations, such as
opening and
closing, are composite processes that utilize both dilation and erosion to modify the structure of an image. These operations are particularly useful for tasks such as noise removal, shape smoothing, and object separation. •
Opening: This operation is performed by applying erosion to an image first, followed by dilation. The purpose of opening is to remove small objects or noise from the foreground while preserving the overall structure of larger objects. It is especially effective in situations where noise appears as isolated bright pixels or small, disconnected features. For example, applying opening to an image f with a structuring element B would first reduce small details (through erosion) and then restore the main shapes (through dilation). This ensures that unwanted noise is removed without significantly altering the size or shape of larger objects. •
Closing: This operation is performed by applying dilation first, followed by erosion. Closing is typically used to fill small holes or gaps within objects and to connect broken parts of the foreground. It works by initially expanding the boundaries of objects (through dilation) and then refining the boundaries (through erosion). For instance, applying closing to the same image f would fill in small gaps within objects, such as connecting breaks in thin lines or closing small holes, while ensuring that the surrounding areas are not significantly affected. Both opening and closing can be visualized as ways of refining the structure of an image: opening simplifies and removes small, unnecessary details, while closing consolidates and connects objects to form more cohesive structures. ==Applications==