Checking the type of Image in '' if '' statement

조회 수: 3 (최근 30일)
Dimitris M
Dimitris M 2012년 6월 26일
Hello
I have a simple question that bother me a lot in making a function. I want the function to take as input either a label image or rgb image. I do not know how to program the function to check what is the format of the input image and the process it accordingly.
Is there a simple way to determine between two input image formats ?
Thank you in advance

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 26일
RGB images have 3 dimensions. Label images do not (well, not unless you label a 3 dimensional object.)
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 6월 26일
You cannot tell the difference between a label image that contains only 0 and 1 for labels, compared to a grayscale image that uses 0 for black and 1 for white and no other values. Both images would be floating point and the same range.
grayscale images can be an integer data type. Label images will (as far as I _remember_ be produced as floating point. But grayscale images can be floating point as well, in which case their values must be between 0 and 1. If you have a floating point array that has a value above 1 then it cannot be a grayscale image.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Dimitris M
Dimitris M 2012년 6월 26일
Yes, this is correct but in some cases I introduce grayscale image (not mentioned above) . Is there a general solution for reading in information about every kind of image ?
Thank you

Community Treasure Hunt

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

Start Hunting!

Translated by