且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何添加和删除图像中的噪音

更新时间:2022-10-23 11:08:19

从您的评论背景和您提出的问题来看,您希望完全删除来自已损坏图像的噪音。如果首先您知道噪声输入过程的脉冲响应/点扩散函数(PSF),则只能完全删除。了解PSF并使用此功能进行噪声消除通常称为。



关于你可以消除噪音的程度,这完全取决于反复试验。您只需使用不同的过滤器大小和参数过滤图像,直到您获得您认为的感知质量良好或使用所有试验中具有最高PSNR的图像。显然,您的图像越嘈杂,您制作滤镜的过程就越激进,但您可能无法识别原始图像的样子。



这主要是一个试错过程,因此您必须使用参数并查看所获得的内容。






我希望这已经充分回答了你的问题。祝你好运!


I want to add gaussian noise to a 256x256 greyscale image and then remove it. I tried doing using the following code but all I get is an image which has noise alone. Is it possible to completely remove the noise from the image? And if not to what extent can gaussian noise be reduced?

 P =0;  %mean
 Q =0.01; %variance
 R = imnoise(L,'gaussian',P,Q); %L-image
 subplot(2,1,1);
 imshow(R);
 title('Gaussian Noise');

 U = conv2(double(R), ones(3)/9, 'same');
 U1=uint8(U);
 subplot(2,1,2);
 imshow(U1);
 title('Median Filtered Image');

I'm planning to implement addition and removal of Poisson noise and Salt and pepper noise as well. Kindly suggest me if there is a filter to remove these noises too. Please help. Thanks in advance.

Judging from the context of your comments and the question you're asking, you wish to completely remove the noise from an already corrupted image. You can only do a complete removal if you know the impulse response / point spread function (PSF) of the noise input process in the first place. Knowing the PSF and doing a noise removal with this is commonly known as deconvolution. Because the PSF of a random noise process is seldom known in practice and the fact that noise is a random process, it is practically impossible to completely remove all the noise. There are certainly models of noise that exist, but knowing the exact parameters of the noise model that corrupted your image is very difficult (if not, impossible...) to determine.

You can certainly remove most of it and you will not get the original image back, but you can mitigate the noise through standard noise filtering techniques. To remove Gaussian noise, you can simply use any standard low-pass filtering method, such as average filtering or Gaussian filtering. You can also use Wiener filtering where it is an adaptive filter. It analyzes the pixel neighbourhoods of your image and computes the variance of each neighbourhood. If the variance is small, more smoothing is performed and vice-versa. Take a look at this link for a good example.


Now, in your code you have posted, you have opted to use conv2. One small thing I will point out is that your filtering code does not do median filtering. You are implementing an average filter. If you want to use median filtering, use medfilt2 instead.

In any case, though conv2 is great for any 2D signal in general, I would recommend you use imfilter instead. It is specifically designed to filter images (linear filtering actually...), and it also takes advantage of the Intel's IPP library should your computer / processor support its use. I tried running your code (using conv2) on my machine with the standard cameraman.tif image and I get an output that isn't blank as mentioned in your comments. My guess is that you're getting a blank image due to the casting to uint8. L was most likely converted to a double precision image that ranges between [0,1] and when you simply cast to uint8, you'll only get an image that has intensities of 0 or 1 which is why you don't see anything. Try converting your image using im2uint8 so that you can contrast normalize the intensities to [0,255] instead for suitable display with imshow.

However, if you use imfilter, there is no need to convert types as imfilter will respect whatever the type of the input image was and will use that same type for the output image. As such, make your code look something like this:

L = imread('cameraman.tif'); %// Load in image from MATLAB system path 
P =0;  %mean
Q =0.01; %variance
R = imnoise(L,'gaussian',P,Q); %L-image
subplot(2,1,1);
imshow(R);
title('Gaussian Noise');

U = imfilter(R, ones(3)/9, 'replicate');   %// Change - Use imfilter
subplot(2,1,2);
imshow(U);
title('Average Filtered Image'); %// Changed title to be correct

This is what I get:


Now, to answer your questions about the different kinds of noise you want to filter, Poisson noise can be filtered by low-pass filters as well (average, Gaussian, etc.). Salt and pepper noise is best filtered with median filtering. Here's a great example on how median filtering works for salt and pepper noise.

As to what "extent" you can remove the noise, that totally depends on trial and error. You simply have to keep filtering your image with different filter sizes and parameters until you get what you believe is perceptually good quality or using the image with the highest PSNR out of all of your trials. Obviously, the more noisy your image is, the more aggressive you need to make your filter, but you risk not being able to recognize what the original image looked like in the first place.

This is mostly a trial and error process, so you'll have to play around with the parameters and see what you get.


I hope this has adequately answered your questions. Good luck!