"Carl S." wrote in message <kbi19e$f3q$
1...@newscl01ah.mathworks.com>...
> I have two images. They are;
> tempBinaryImg : 320x320 double
> GrayscaleImg : 320x320 double
>
> When I write that
> temp2 = tempBinaryImg.*(GrayscaleImg>0);
> PreprocessedGrayscaleImg = uint8(Img).*uint8(temp2);
>
> then I am getting PreprocessedGrayscaleImg as uint8. But I want to get the PreprocessedGrayscaleImg as double. So, I write
>
> PgrayImg = double(PreprocessedGrayscaleImg);
>
> but the PgrayImg is binary, it is not gray. How can I get the PreprocessedGrayscaleImg as double and gray ?
----------------------------------------------------------------------------------------------------------
It's not binary. It's a gray scale image of type "double". Why? Do "whos PgrayImg" to see the data type of PgrayImg, or else look in the Workspace panel. But why does it have values of only 0.0 and 1.0? Well let's take it a step at a time:
(GrayscaleImg>0) is a logical (0's and 1's), but gets converted to double to do the multiplication.
tempBinaryImg is double, but judging from the name, it also has values of 0's and 1's.
So the product temp2, will also be a double but have values of 0.0 and 1.0 only.
So now you cast temp2 to uint8 which means it's now unsigned 8 bit integer and will have integer (not floating point) values of 0 and 1.
Then you have some array "img" and I have no idea what values it has, but after you cast it to uint8, it will have integer values of 0, 1, 2, 3, ....255, or whatever it actually contains.
So you do uint8(Img).*uint8(temp2) and you will get PreprocessedGrayscaleImg as a uint8 also, and it will have values of 0, 2, 3, 4, ... 255 or the same values that img, masked by temp2, would have. And now you do this:
PgrayImg = double(PreprocessedGrayscaleImg);
which means that PgrayImg has the same values as PreprocessedGrayscaleImg but they are double instead of integer, in other words floating point 0.0, 1.0, 2.0, 3.0, ...255.0, or whatever values the masked version of tempBinaryImg has.
You said you think it's binary (type logical), but it's not - it's double, though it might have floating point values of 0.0 and 1.0 only, if that's what tempBinaryImg had.