开发者

Binary image in Matlab

How can I know if an image read w开发者_StackOverflow社区ith imread is binary in MATLAB

I did this :

Img = imread(IMGsrc);

T = Img== 1 | Img == 0;

If min(min(T)) == ??????

    imshow(T);

end

????? = ??????


There are two ways you can test for binary images.

The simplest one is to test whether the image is a logical array (a logical array is returned by functions in the image processing toolbox that return binary image)

isBinaryImage = islogical(img);

Alternatively, you check whether all pixels are either 1 or 0

isBinaryImage = all( img(:)==0 | img(:)==1);


Assuming by "binary" you mean "every pixel is either 1 or 0", a couple things given your image I:

  • size(I) should only return rows and columns (not channels) otherwise it is not binary
  • You can test every pixel is either 1 or 0 with T = I == 1 | I == 0;. If min(min(T)) comes back anything but 1 then at least one pixel failed that test, meaning there is a value that is neither 0 nor 1. (For that matter you could use a similar test to check for any number of enumerated values, not just 0 and 1.)

If you can further clarify what you mean by "binary" that would go a long way to a better answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜