Data type required for EDT using PyDIP #179
-
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') when I run: d1 = dip.EuclideanDistanceTransform(img1) - dip.EuclideanDistanceTransform(~img1) I get the error: Traceback (most recent call last): 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! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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
You can query the data type using To convert a gray-scale image to binary, threshold it. In your example, you could do
If your image is RGB, not gray-scale, you could extract any of the channels: |
Beta Was this translation helpful? Give feedback.
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, thenprint(img1)
will show you something like this: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 doimg1.Convert('BIN')
, usedip.Threshold()
, etc. Nowprint(img1)
shows something like this: