Many of the Ops in BoneJ2 are only meant to work with binary images, so I often need to check the open image before passing it down. A binary image is any image that contains only two distinct values, e.g. black & white. I was suggested that a fast and general way to check this would be:
final Class<?> elementClass = interval.firstElement().getClass(); final boolean isBinary = BooleanType.class.isAssignableFrom(elementClass);
Now this works fine in unit tests where I create a
Dataset whose elements are
BitType etc. The thing is, it doesn’t work that well in the real world. For example, the sample image “Bat Cochlea Volume” fails this test (element type is
UnsignedByteType). Furthermore, even if I binarize an image (Process > Binary > Make Binary) the result won’t pass the test.
Any ideas how to test
Dataset for this property? You could always brute force and go through all the elements in the interval, but that’s not a very good solution…