why doesn't Graythresh work with the format "double"?

3 views (last 30 days)
I have an image (gray scale, 0-255) in the form of "uint8". I only need a part of it and as such I do the following:
Part_of_the_Image=original_Image(1:H,1:W);
the above, gives me an Image in the form "double". If I plot it (via imagesc and setting the colormap to gray), I would get a "white" image in the figure. In addition, the "graythresh" function does not work on it either (would give 0 as the threshold).
All of the problems are NOT encountered if I convert "Part_of_the_Image" to uint8.
I am just wondering why "double" yields to such problems!
Any comment would be appreciated.

Accepted Answer

Image Analyst
Image Analyst on 19 Jun 2014
If your original_Image is truly uint8, then Part_of_the_Image will also be uint8. It will not convert it. Use class() or whos() to check. Post proof if you think otherwise. Here's my proof:
original_Image = 255 * ones(200, 'uint8');
H = 15;
W = 9;
Part_of_the_Image = original_Image(1:H,1:W);
whos original_Image
whos Part_of_the_Image
In the command window:
Name Size Bytes Class Attributes
original_Image 200x200 40000 uint8
Name Size Bytes Class Attributes
Part_of_the_Image 15x9 135 uint8
If an image is floating point, it's expected to be in the range 0-1 and pixels outside that range will be black or white. If you have some arbitrary range that's different than that, you can display the full dynamic range with [] option in imshow():
imshow(doubleImage, []);
  2 Comments
ramin bba
ramin bba on 19 Jun 2014
The problem was I predefined the variable as zeros(), which makes it "double".
however, I still do not know why some functions (Graythresh or imagesc) do not work when the format is double! in the documentation it is stated that the input can be of the form "double".
Image Analyst
Image Analyst on 19 Jun 2014
You can pass in 'uint8' into zeros() and ones() like I did to make it be uint8.
graythresh() can take a double but, like with all image processing toolbox functions, it needs to be in the range 0-1. It's a pain so I never use it.
I don't see anything in the help about imagesc() taking doubles. If this answers your questions, please vote for and Accept the Answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!