Write a function to add random noise to an image in matlab

4 vues (au cours des 30 derniers jours)
Krish Desai
Krish Desai le 9 Oct 2015
Commenté : Image Analyst le 18 Sep 2019
How do I create a function to add random noise without using imnoise? I am trying to figure out how to do it without using the built-in matlab functions. I know I have to add a random integer to every pixel...
function output=randomnoise(current_img)
for current_img(n)
current_img(n)=current_img(n)+ randi([-255 255],1)
n=n+1
end
This is what I am coming up with right now, but I don't think my loop is visiting each value. How do I visit each pixel and how do I add random noise to it?
  1 commentaire
Walter Roberson
Walter Roberson le 9 Oct 2015
The distribution of random value you add to the pixel is important.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 10 Oct 2015
Try this:
function output=randomnoise(current_img)
% Cast to double;
current_img = double(current_img);
[rows, columns] = size(current_img)
for col = 1 : columns
for row = 1 : rows
output(row, col) = current_img(row, col)+ randi([-255 255],1)
end
end
Or you could do away the the two loops and just vectorize it
noise = randi([-255, 255], rows, columns);
output = current_img + noise;

Plus de réponses (2)

Walter Roberson
Walter Roberson le 9 Oct 2015

Arifaa A
Arifaa A le 18 Sep 2019
function output=randomnoise(current_img)
% Cast to double;
current_img = double(current_img);
[rows, columns] = size(current_img)
for col = 1 : columns
for row = 1 : rows
output(row, col) = current_img(row, col)+ randi([-255 255],1)
end
end
noise = randi([-255, 255], rows, columns);
output = current_img + noise;
  1 commentaire
Image Analyst
Image Analyst le 18 Sep 2019
How is that different than my code? It looks identical.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by