How to make a custom kernel for extraction?

asked 2019-08-14 08:26:45 -0600

SagRU gravatar image

Hello,

I use morphological opening to extract horizontal lines from my image:

<...uploading an image and binarizing it...>    
kernel_2 = np.ones((1,7), np.uint8)
hor_opening = cv2.morphologyEx(binary_img, cv2.MORPH_OPEN, kernel)

It works perfectly, but what should I do to use a kernel that combines ones and zeros? I want to extract from my image all segments that satisfy a following mask: [0, 1, 1, 1, 1, 1, 1, 1, 0]

edit retag flag offensive close merge delete

Comments

1

How about filling the numpy array first with ones, like you did and then change the values behind the correct indices to 0? Seems quite straightforward right?

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-19 09:26:20 -0600 )edit