A is less than a threshold
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rocky
am 15 Apr. 2020
Kommentiert: Rocky
am 16 Apr. 2020
m=256;
e=0.5;
for x=1:m
for y=1:m
if A(x,y)<0.5
s_dark(x,y)=A(x,y)^e;
end
end
end
Hello everyone.I have some problem in this code.The values less than 0.5 shold be stored in a variable s_dark.But i didn't get it.It store values less than 0.5 and also greater than 0.5.I've attached the s_dark variable below.please see through it.your help is really appreciated.
0 Kommentare
Akzeptierte Antwort
Mehmed Saad
am 15 Apr. 2020
Bearbeitet: Mehmed Saad
am 15 Apr. 2020
Because in your code
s_dark(x,y)=A(x,y)^e;
suppose A(x,y) = 0.47;
where e = 0.5;
0.47^0.5
ans =
0.6856
That is why you are getting values greater than 0.5
i think what you are trying to do is
m=256;
e=0.5;
A = A.^e;
for x=1:m
for y=1:m
if A(x,y)<0.5
s_dark(x,y)=A(x,y);
end
end
end
i am assuming that s_dark is initialized in the code earlier
9 Kommentare
Weitere Antworten (1)
Image Analyst
am 15 Apr. 2020
Not exactly sure what you want where A > 0.5, a value of 0 or of the original A? So here are both options:
% Initialization steps.
m = 256;
A = 0.7 * rand(m, m)
e = 0.5;
% OPTION 1
% s_dark equals A except where A is less than 0.5 where
% it will replace values of A less than 0.5 with
% the value raised to the e power
s_dark = A; % Initialize;
map = A < 0.5; % Logical matrix of where A is less than 0.5.
s_dark(map) = A(map) .^ e;
% OPTION 2
% s_dark equals 0 except where A is less than 0.5 where
% it will be the values of A raised to the e power
s_dark = zeros(size(A)); % Initialize;
map = A < 0.5; % Logical matrix of where A is less than 0.5.
s_dark(map) = A(map) .^ e;
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!