[Digital Image Processing] Four commonly used filters

digital image processing


1. Smoothing filter

1.1 Basic principles

Spatial filtering is to move the template point by point on the image to be processed f (x, y), and the filter response at each point (x, y) is calculated through a pre-defined relationship. This response is the output of spatial filtering.

1.2 Function

  • Blur processing to remove some unimportant details in the image;
  • Eliminate the high-frequency components in the image without affecting the low-frequency components; the high-frequency components correspond to areas with large changes in grayscale values ​​such as edges on the way, and smoothing can reduce these fluctuations;
  • Reduce or eliminate noise;
  • Remove details that are too small or connect small discontinuities in an object before extracting a larger object.

1.3 Neighborhood weighted average implementation method

Neighborhood weighted average: The mean or weighted average of the pixels contained in the filter neighborhood, also called a mean filter.
When the filtering center is on the edge of the image, there are two processing methods:

  • No processing is performed, and the output at the edge is equal to the input;
  • Or "padding" a number of rows and columns to the input image, padding with zeros, padding with the same value, and symmetrical padding.

2. Gaussian filter

2.1 Basic principles

Insert image description here

2.2 Features

Insert image description here

3. Median filter

3.1 Basic principles

The basic principle of median filtering is simply to use the median value of the pixels in the template area as the result value.

3.2 Applicable occasions

The main purpose:

  • remove noise
  • Forces highlighted bright spots (dark spots) to be more like the values ​​around it to eliminate isolated bright spots (dark spots)

Calculation formula:R=mid{zi|i=1,2,…,n}

3.3 Implementation method

  • Sort the pixels in the template area, arrange them continuously for pixels of the same value, and find the intermediate value (for example: for a 3x3 template, the fifth largest one is the intermediate value)
  • Take a 3X3 window, arrange it from small to large, and take the middle value as the value of this area.

3.4 Features

  • advantage:
  • While removing noise, the edge sharpness and image details can be better preserved (better than the mean filter);
  • Can effectively remove impulse noise: salt and pepper noise superimposed on the image with black and white dots
  • shortcoming:
  • Median filtering removes isolated line or point interference while retaining spatial clarity and is worse than smoothing filtering; however, it is not as good as smoothing filtering for Gaussian noise.
  • Image edges move

4. Laplacian sharpening filter

4.1 Basic principles

Sudden changes in grayscale:The wave peak formed after one differentiation represents the edge of the two regions.. If the wave crest is high enough, that is, it has exceeded the threshold, it is enough to indicate that there is an edge formed by an edge point there.

4.2 Purpose

  • Enhance high-frequency components in images;
  • It is often used to enhance blurred details or the edges of objects to enhance the details of the image.

4.3 Applicable occasions

The main purpose:

  • Highlight details in the image and enhance blurred details;
  • Subtle levels of emphasis in typography. Compensate for the passivation of images caused by scanning;
  • Ultrasound detection imaging has low resolution and blurred edges, which can be improved by sharpening;
  • In image recognition, edge extraction before segmentation;
  • Sharpening process restores overly dull and underexposed images;
  • Zero point detection.

4.4 Implementation method

Laplacian
Insert image description here

5. Matlab code implementation

%引入图片
I=imread('你的路径');

5.1 Smoothing filter

%% 平滑滤波
%制定卷积核为3×3的全1矩阵
h=ones(3,3)/9;
%平滑运算
I_average=imfilter(I,h);
figure(f1);
subplot(2,2,1);imshow(I_average);title('平滑滤波图像');

5.2 Gaussian filtering

%% 高斯滤波
% 标准差为1的高斯滤波器
I_Gauss = imgaussfilt(I,1);
figure(f1);subplot(2,2,2);imshow(I_Gauss);title('高斯滤波图像');

5.3 Median filtering

%% 中值滤波
% 3×3的邻域中值滤波
I_mid = medfilt2(I);
figure(f1);subplot(2,2,3);imshow(I_mid);title('中值滤波图像');

5.4 Laplacian sharpening filter

%% 拉普拉斯锐化
% 4邻点拉普拉斯锐化滤波器
H = fspecial('laplacian',0);
I_lap = double(I);
I_laplacian = imfilter(I_lap,H);
figure(f1);subplot(2,2,4);imshow(I_laplacian);title('拉普拉斯锐化滤波图像');

Guess you like

Origin blog.csdn.net/The___sky_/article/details/128469248