Skip to content Skip to sidebar Skip to footer

Opencv3: Not Getting The Expected Output On Morphologically Transforming An Image In Opencv

I am trying to do top hat morphological transformation to an image but not getting the expected output for some reason. # Top Hat: difference between input image and opening kernel

Solution 1:

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, ksize=(9,9))
tophat = cv2.morphologyEx(image, cv2.MORPH_TOPHAT, kernel)

result

Edit:

For details please read the following:

https://docs.opencv.org/3.3.1/d9/d61/tutorial_py_morphological_ops.html

https://docs.opencv.org/3.3.1/d4/d86/group__imgproc__filter.html#gac342a1bb6eabf6f55c803b09268e36dc

Iterations vs. Kernel Size in Morphological Operations (OpenCV)

Solution 2:

Do you need to normalize your kernel? Try removing the division by 25 from the kernel.

Morphological kernels are supposed to be consist of "ones" and "zeros". Therefore, no normalization is required. It will work fine with type CV_8UC1 as well.

Post a Comment for "Opencv3: Not Getting The Expected Output On Morphologically Transforming An Image In Opencv"