Strange result morphological filtering with opening and closing

asked 2017-05-17 00:00:55 -0500

Kenny Karnama gravatar image

updated 2017-05-17 04:36:41 -0500

Hi guys, i try to filter binarized image using closing and opening operation in morphological filtering. But, why the image completely damage ? (note: i have tried to invert the image). Is my kernel / structure element wrong ? Thanks.

initial image

invert the image :

invert image


filtered image

as an information, i use 3 x 3 disk structuring element

Mat k = getStructuringElement(MORPH_ELLIPSE,Size(3,3));

here is my opencv code :

Mat k = getStructuringElement(MORPH_ELLIPSE,Size(3,3));

morphologyEx( thresholdImg, openingImg, 3, k );
morphologyEx( openingImg, finalMorph, 2, k );
edit retag flag offensive close merge delete


note, that white things on black bg are expected here, if you have black contours, erode and dilate swap their meaning.

berak gravatar imageberak ( 2017-05-17 01:00:23 -0500 )edit

can you explain more detail ? i still don't understand

Kenny Karnama gravatar imageKenny Karnama ( 2017-05-17 02:59:24 -0500 )edit

have a look at the erode / morphology tutorials

you probably have to invert your image (maybe using THRESH_INVERT) before applying the morphology ops.

berak gravatar imageberak ( 2017-05-17 03:04:39 -0500 )edit

This result seems consistent with your code. If you are trying to achieve some other result we need to know what it is that you are trying to do :)

Pedro Batista gravatar imagePedro Batista ( 2017-05-17 06:31:30 -0500 )edit