Applying changes to an image, but it's not working, no error yet!

1 view (last 30 days)
Here's my code:
File_XX = fopen('..\Data\AA.DAT');
IMG = fread(File_XX, '*float');
fclose(File_XX);
IMG = reshape(IMG,256,256,50);
MX = max(max(max(IMG)));
IMG = IMG/MX;
for i = 1 : 256
for j = 1 : 256
for k = 1 : 50
if(IMG0(i,j,k) == 2)
IMG(i,j,k) = 10;
end
end
end
end
File_IMG = fopen('Out2\Masked_AA', 'w');
fwrite(File_IMG, IMG, '*float');
fclose(File_IMG);
imshow(IMG0(:,:,iii)); title('FCM C_p Mask');
figure, imshow(IMG(:,:,iii)); title('AA Masked')
It displays the image unaltered, I don't know where's the problem

Accepted Answer

Image Analyst
Image Analyst on 27 Dec 2013
The whole triple for loop can be replaces by these two lines:
binaryImage = IMG0 == 2;
IMG(binaryImage) = 10;
But of course you must have defined IMG0 first. If the image is unaltered then either (1) the binary image is false everywhere meaning IMG0 never equals 2 anywhere, or (2) IMG was already 10 in the locations where IMG0 equaled 2 (actually which can't be true because you normalized IMG).
By the way, iii is never defined either. So I'm pretty sure this is not the code you ran .
I suspect the problem is that you normalized IMG0 just like you did IMG and so it will never equal 2 and so IMG will never get changed to 10.
  1 Comment
M
M on 27 Dec 2013
THANK YOU VERY MUCH
IMG0 was defined earlier in the code, the problem was in its normalization line, it worked after fixing it

Sign in to comment.

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!