David
David

Reputation: 157

Python Opencv morphological closing gives src data type = 0 is not supported

I'm trying to morphologically close a volume with a ball structuring element created by the function SE3 = skimage.morphology.ball(8). When using closing = cv2.morphologyEx(volume_start, cv2.MORPH_CLOSE, SE) it returns TypeError: src data type = 0 is not supported Do you know how to solve this issue? Thank you

Upvotes: 9

Views: 21857

Answers (2)

Daniel Azemar
Daniel Azemar

Reputation: 555

Make sure volume_start is dtype=uint8. You can convert it with volume_start = np.array(volume_start, dtype=np.uint8).

Or nicer: volume_start = volume_start.astype(np.uint8)

Upvotes: 14

Aleksandar
Aleksandar

Reputation: 4154

The same error occurred to me while calling the erode function on a binarized image that I binarized (from a grayscale image of 0 to 255 values) like this:

bin_img = grayscale_img > 125

I guess the > operator "swallowed" the type, or changed it to the openCV's type of code 0.

I solved it by doing the binarization like this:

ret, bin_img = cv2.threshold(grayscale, 125, 255, cv2.THRESH_BINARY)

ret is the threshold value (125 in this case), and bin_img is the resulting binary image.

Upvotes: 0

Related Questions