Creating noise in an image unconventionally

1 次查看(过去 30 天)
I have tried the imnoise funtion with my image (a gaussian beam) and none of the options seem to work. The problem is that because it fades out to very small numbers the imnoise function rounds it all to 1 and does not show what I'm looking for.
Anyways what I am looking for help with is how to make this work:
x = rand(size(Beam)); # I created a matrix the size of the image between 0 and 1
x = x<0.2; # removed 80% of the values and am left with 0's and 1's. 20% being a 1.
z = Beam+x; # added x to the beam
n = rand(size(Beam))*250 # created a matrix of random numbers between 0 and 250 the size of the beam.
# the if statement was an attempt to have it so that wherever there was a 1 in x that same value in the image would get replaced by the corresponding number in n (wherever z =x+1)
if z>Beam
Beam = n;
end
The goal is to have a random 20% (subject to change) of the image as random numbers between 0 and 250
Any help is appreciated.
Cheers,
Ollie

采纳的回答

Walter Roberson
Walter Roberson 2021-1-21
x = rand(size(Beam)) < 0.2; %logical array!
z = Beam;
n = rand(1,nnz(x)) * 250;
z(x) = n;

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by