Apply a non defined noise to an image

9 visualizzazioni (ultimi 30 giorni)
Ana Gabriela Guedes
Ana Gabriela Guedes il 30 Nov 2021
Risposto: yanqi liu il 30 Nov 2021
Hello!
I have a user defined function that lets us set some kinds of noise and I want to apply that noise to an image. How can I do this since the imfilter function only allows us to apply pre defined noises?
Thank you in advance
  2 Commenti
Image Analyst
Image Analyst il 30 Nov 2021
Modificato: Image Analyst il 30 Nov 2021
imfilter() does not apply noise. Maybe you got it confused with imnoise().
You're going to have to be more specific than that. For example is the noise independent of the signal and adds onto it? Or does the noise depend on the value of the signal? Give an example of some noise function that you might want to apply.
Ana Gabriela Guedes
Ana Gabriela Guedes il 30 Nov 2021
I have the following function (that also depends on other functions)
function [noise, PSD, kernel] = getExperimentNoise(noise_type, noise_var, realization, sz)
randn('seed',realization);
% Get pre-specified kernel
kernel = getExperimentKernel(noise_type, noise_var, sz);
% Create noisy image
half_kernel = ceil(size(kernel) ./ 2);
if(numel(sz) == 3 && numel(half_kernel) == 2)
half_kernel(3) = 0;
end
% Crop edges
noise = convn(randn(sz + 2 * half_kernel), kernel(end:-1:1,end:-1:1, :), 'same');
noise = noise(1+half_kernel(1):end-half_kernel(1), 1+half_kernel(2):end-half_kernel(2), :);
PSD = abs(fft2(kernel, sz(1), sz(2))).^2 * sz(1) * sz(2);
end
and I use it to create 3 different types of noises: additive Gaussian white noise gw with variance 0.04, circular repeating pattern noise g2 with variance 0.04 and diagonal line pattern noise g3 with variance 0.04:
I = im2double(imread('lighthouse.png'));
gausN = getExperimentNoise('gw',0.04,0,size(I));
cRepN = getExperimentNoise('g2',0.04,0,size(I));
dLineN = getExperimentNoise('g3',0.04,0,size(I));
And now I want to apply this noises to the original image. How can I do it? (I know I could use imnoise() for the gaussian but the exercise really needs us to use the given functions)

Accedi per commentare.

Risposte (1)

yanqi liu
yanqi liu il 30 Nov 2021
yes,sir,may be define the noise matrix and add to image ,such as
x = imread('carmeraman.tif');
nx = double(x) + 18*randn(size(x));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by