i have following image in double(i.e range is 0-1) & i want to convert it to 1's and -1's form,just convert 0 to -1.i tried foll code but its not working.please help. :(
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
%%just try the foll code:
[d1,d2,d3]=size(img);
for i=1:d1
for j=1:d2
if img(i,j)==0
img(i,j)=-1
end
end
end
%display it and see impixelinfo;
%0 should get converted to -1
%and 1 as it is.
take attached sample img.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150836/image.png)
0 commentaires
Réponses (1)
David Sanchez
le 18 Oct 2013
I=rgb2gray(rp7);
I2=im2bw(I);
I3 = double(I2);
I3(I2==0) = -1;
2 commentaires
Walter Roberson
le 18 Oct 2013
Or once I3 has been created,
I3 = I3 * 2 - 1;
without using the logical indexing.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!