如何使用matlab中的滤镜去除图像中的多频噪声?

时间:2016-05-25 16:55:18

标签: matlab noise

我的图像有多频噪声,我使用了此链接中的代码: Find proper notch filter to remove pattern from image 源图片:orig_image 但我的最终图像噪音尚未消除。 如您所知,我必须在垂直方向上移除渐变。图像的频率表示如下: fft of image 有没有人想过在matlab中消除这种噪音? 我使用sobel滤波器和中值滤波器但没有改进。 请注意,我的目标是删除对象内部的行。 问候。

2 个答案:

答案 0 :(得分:1)

你有两种噪音:不规则的水平线和盐和胡椒。只要物体不覆盖整个水平范围(在你的例子中它没有),摆脱线条很容易。

我只是在左边采样一个小的垂直条纹,只得到条纹,然后从整个图像中减去它们。使用中值滤波器去除盐和胡椒噪声很简单。

结果: enter image description here

代码:

% read the image
img = imread('http://i.stack.imgur.com/zBEFP.png');
img = double(img(:, :, 1)); % PNG is uint8 RGB

% take mean of columsn 100..200 and subtract from all columns
lines = mean(img(:, 100:200), 2);
img = img - repmat(lines, 1, size(img, 2));

% remove salt and pepper noise
img =medfilt2(img, [3,3], 'symmetric');

% display and save
imagesc(img); axis image; colormap(gray);
imwrite((img - min(img(:))) / (max(img(:)) - min(img(:))), 'car.png');

答案 1 :(得分:0)

这里是曾经用于我曾经做过的任务的代码。这是一个比你拥有的更简单的例子。频域中总共只有4个分量会产生噪声,因此只需手动将这4个分量设置为零(hfreq)即可解决我的问题。我不知道这对你的情况有多好,也许写一个算法来找到合适的hfreqs会有所帮助。 这是我使用的原始图像:

这是我使用的代码:

    %  filtering out the noisy image

clc
clear all
close all

image = imread('freqnoisy.png');

image = double(image);
image = image/(max(max(image)));

imshow(image) % show original image

Fimage = fft2(image); 

figure
imshow(((fftshift(abs(Fimage)))),[0 5000]) %shows all frequency peaks that stick out


hfreq = ones(256);

hfreq(193,193)=0;
hfreq(65,65) = 0;


hfreq(119,105) = 0;
hfreq(139,153)= 0;



% 
Fimage_filtered = fftshift(Fimage).*hfreq;



figure
imshow(abs(Fimage_filtered),[0 5000]) % show freq domain without undesired freq

filtered_im = ifft2(ifftshift(Fimage_filtered));
figure
imshow(filtered_im)

这就是你的输出结果:

enter image description here