Digital Image Processing: Overlimit Neighborhood Averaging Method (Threshold Method)

The image polluted by Gaussian noise (the noise intensity is set to 0.05) is filtered by the over-limit neighborhood averaging method (threshold method), and the Gaussian mask can be used for neighborhood averaging (as shown below).
Matlab program: (version 2016a)
script: test2.m:


1.	% 超限邻域滤波  
2.	clc,clear,close all % 清理命令区、清理工作区、关闭显示图形  
3.	feature jit off % 加速代码运行  
4.	img = imread('hua.jpg');  
5.	img1 = imnoise(img,'gaussian',0.05);%加入噪声密度:0.05的高斯噪声  
6.	img2=rgb2gray(img1);  
7.	img3 = threddmean_filter( img2,5, 5/255 ); % 应用超限邻域滤波  
8.	figure('color',[1,1,1])  
9.	  
10.	subplot(221),imshow(img,[]),title('original image')  
11.	subplot(222),imshow(img1,[]),title('gaussian image')  
12.	subplot(223),imshow(img2,[]),title('灰度图')  
13.	subplot(224),imshow(img3,[]),title('超限邻域滤波效果图')  
可选:效果优化
1.	colormap(jet) % 颜色  
2.	shading interp % 消隐  

Function: threddmean_filter.m:


1.	function Z = threddmean_filter(X,n,thred)  
2.	% 函数对输人图像进行超限邻域平均法滤波  
3.	% 函数输入  
4.	% X:输人二维图像矩阵  
5.	% n:掩膜尺寸  
6.	% thred:阈值  
7.	% 函数输出  
8.	% Z:输出图像矩阵,数据类型与输人相同  
9.	if size(X,3)~=1  
10.	error('图像应该为2维矩阵')  
11.	end  
12.	if ~isa(X,'double')  
13.	X = double(X)/255; % 数据类型  
14.	end  
15.	H = fspecial('average',n); % 均值模板  
16.	Y = imfilter(X, H);  
17.	thre = abs(X-Y)>thred; % 判断哪些是门限  
18.	Z = X; % 赋值  
19.	Z(thre)=Y(thre);  
20.	Z = im2uint8(Z); % 类型转换  
21.	end  
  1. Original image, processed image;
    without color effect display:
    insert image description here

Add color effect display:
insert image description here

  1. Explanation of the process and results of the processing:
    Reference resources: Web page link
    Consulting information: This program mainly refers to website resources, but an error occurs when it is run for the first time, prompting that the image input by the overlimit neighborhood filter function is not a two-dimensional matrix, The error analysis is that there is no image grayscale processing, use the data and rgb2gray function to process the image, and then input the result map into the overlimit neighborhood filter function.
    Programming logic:
    Similar to the previous processing method, the image is preprocessed first. The core of programming is the over-limit neighborhood method, and an over-limit neighborhood filter function is used to complete the function of the over-limit neighborhood filter; the over-limit filter function
    idea :
  1. The overlimit filter function has three input values: image, mask, and filter threshold (threshold range is 0-255)
  2. Determine whether the input image format is correct
  3. After the input image format is correct, set the mean template H
  4. Use the imfilter function to obtain the pixel average value of the input image X and assign it to Y
  5. Use abs(XY) to find points in the image greater than the threshold thred

  6. The idea of ​​​​replacing these points with the mean value of the neighborhood pixels is to use the mean value or weighted mean value of the pixel and the pixels in the specified neighborhood as the new value of the pixel, so as to remove the abrupt pixel points, thereby filtering out certain noise. In order to solve the image blur problem caused by the neighborhood averaging method, the threshold method (also known as the overlimit neighborhood averaging method, if the gray value of a pixel is greater than the average value of its neighboring pixels and reaches a certain level, the pixel is judged If it is noise, then replace this pixel value with the mean value of the neighboring pixels; otherwise, the pixel is considered not to be a noise point and will not be replaced.
    Analysis: When the threshold is different, the effect is also different, and the small noise is always filtered out first, However, the threshold value required for large noise points is reduced; when the threshold value is increased, the noise filtering effect is very good, but at the same time, some details of the original image are lost.

Guess you like

Origin blog.csdn.net/TianHW103/article/details/127956592