Soso Gegechkori
Soso Gegechkori

Reputation: 41

How to apply dilation on particular region of the image?

I have applied dilation on the whole image (img) but bold text/logo on the upper left corner is still untouched. It happens every time when there is logo or some bold text in the input image

dilated_img = cv2.dilate(img, np.ones((7, 7), np.uint8))

Now I want to re-apply dilation with higher value (> 7) but only on that region. I can't apply dilation with higher value on the whole image because then it gives me poor results. I want to apply low-valued dilation on the whole image and then re-apply high-valued dilation on the regions that haven't got dilated

(This should be generalized on every image and not only this one)

How can I achieve that?

input image

Upvotes: 3

Views: 1088

Answers (1)

ziggy jones
ziggy jones

Reputation: 401

If you want to apply an operation to a rectangular box you can pass in the region by index.

So first dilate the whole image:

dilated_img = cv2.dilate(img, np.ones((5, 5), np.uint8))

Then overwrite the region requiring higher dilation:

dilated_img[10:50, 30:40] = cv2.dilate(img[10:50, 30:40], np.ones((20, 20), np.uint8))

Upvotes: 2

Related Questions