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
댓글 수: 0
채택된 답변
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!