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

3 ビュー (過去 30 日間)
ramin bba
ramin bba 2014 年 6 月 19 日
コメント済み: Image Analyst 2014 年 6 月 19 日
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.

採用された回答

Image Analyst
Image Analyst 2014 年 6 月 19 日
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 件のコメント
ramin bba
ramin bba 2014 年 6 月 19 日
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 2014 年 6 月 19 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by