Closed shbrainard closed 5 years ago
Unlike OpenCV, in DIPlib we make a strong distinction between binary images and gray-scale images. Binary is a distinct type. I presume that your ONE.tif
is an 8-bit unsigned integer image, then print(img1)
will show you something like this:
data type UINT8
sizes {256, 256} (2D)
strides {1, 256}, tensor stride 1
data pointer: 0x104e76000 (shared among 1 images)
origin pointer: 0x104e76000
You can query the data type using img1.DataType()
.
To convert a gray-scale image to binary, threshold it. In your example, you could do img1 = img1 > 0
. You can also do img1.Convert('BIN')
, use dip.Threshold()
, etc. Now print(img1)
shows something like this:
data type BIN
sizes {256, 256} (2D)
strides {1, 256}, tensor stride 1
data pointer: 0x113c85000 (shared among 1 images)
origin pointer: 0x113c85000
If your image is RGB, not gray-scale, you could extract any of the channels: img1 = img1.TensorElement(0)
.
I am using PyDIP on Mac 10.14 (Python 3.6) and am trying to implement the method described here: https://stackoverflow.com/questions/51409818/how-to-average-two-masks using PyDIP.
I am using binary masks (e.g.: https://www.dropbox.com/sh/drpo4xmne2j29zz/AAAggeBmV9r5_KQm9DSdc9cDa?dl=0)
Regardless of whether I import them using cv2 of diplib:
img1 = dip.ImageRead('ONE.tif') img1 = cv2.imread('ONE.tif',cv2.IMREAD_GRAYSCALE)
when I run:
d1 = dip.EuclideanDistanceTransform(img1) - dip.EuclideanDistanceTransform(~img1)
I get the error:
Traceback (most recent call last): File "", line 1, in
RuntimeError: Data type not supported
in function: void dip::EuclideanDistanceTransform(const dip::Image &, dip::Image &, const dip::String &, const dip::String &) (/Users/boat/diplib/src/distance/edt.cpp at line number 1599)
In MATLAB I have to convert these files to logical and resize them all to the same size, but I'm not sure what's required in Python.
Thanks!