改进的图像去噪极值滤波程序 matlab代码
时间: 2024-01-22 22:20:22 浏览: 21
以下是改进的图像去噪极值滤波程序的 Matlab 代码:
```matlab
function [output_image] = improved_median_filter(input_image, window_size)
% Improved Median Filter for Image Denoising
% Input:
% input_image: the noisy input image
% window_size: the size of the window (odd integer)
% Output:
% output_image: the denoised output image
% Pad the input image with zeros
padded_image = padarray(input_image, [(window_size-1)/2 (window_size-1)/2], 'replicate');
% Initialize output image
output_image = input_image;
% Iterate over each pixel in the input image
for i = 1:size(input_image, 1)
for j = 1:size(input_image, 2)
% Extract the current window
window = padded_image(i:i+window_size-1, j:j+window_size-1);
% Sort the window
sorted_window = sort(window(:));
% Compute the median of the sorted window
median_window = sorted_window((window_size^2+1)/2);
% Compute the absolute difference between each pixel in the window
% and the median
abs_diff = abs(window - median_window);
% Compute the maximum absolute difference
max_abs_diff = max(abs_diff(:));
% If the maximum absolute difference is less than the tolerance,
% replace the center pixel with the median
tolerance = 15;
if max_abs_diff < tolerance
output_image(i,j) = median_window;
end
end
end
end
```
注意,这个程序是改进版的中值滤波程序,采用了极值滤波的思想。具体来说,对于每一个窗口,我们先计算其中所有像素与其中位数的差的绝对值,然后取这些差的绝对值的最大值,如果最大值小于一个阈值(这里设为 15),就将中心像素用其中位数替换。这样做的目的是,当一个窗口中存在一个非常明显的离群点时,我们不应该将其中位数作为代表值,而是应该舍弃这个窗口,否则会导致较差的去噪效果。