Binarizing a normalized image is not working properly

1 view (last 30 days)
I have this code to binarize a normalized DTI medical image, it's not working, and I don't understand where is the problem
i
ii=24;
fname = ('SOME_PATH');
F_Name = fopen(fname);
IMG = fread(F_Name, '*float');
fclose(F_Name);
IMG = reshape(IMG,256,256,50);
MX = max(max(max(IMG)));
IMG = IMG/MX;
GM_INDX = IMG(108,148,24);
for l=1:256
for m=1:256
for n=1:50
if (IMG(l,m,n) == GM_INDX)
IMG(l,m,n)=1;
else
IMG(l,m,n)=0;
end
end
end
end
figure, imshow((IMG(:,:,iii))); title('MD.DAT');

Accepted Answer

Image Analyst
Image Analyst on 2 Feb 2014
Probably because it's floating point and there may be only 1 pixel, if any, that match. See the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Try this instead of the triple for loop
tolerance = 0.01; % Whatever.
IMG = IMG > GM_INDX - tolerance & IMG < GM_INDX + tolerance;

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!