How to erode specific part of an image with opencv and python in a fast manner

172 Views Asked by At

I have an image i need to erode, however, there are parts of the image that must be kept intact. Note that for this application, i need as much performance as possible, as i will need to realize this operation a considerable amount of time.

I know i can use a mask to "save" the parts of the image i wish to keep intact and then combine the intact parts with the transformed ones, however, i would like to know if it was possible to tell opencv to simply ignore some pixels based on a condition as this would be faster.

A simple example would be a circle inside of which i have a white pixel, i wish to erode the inside of the circle but protect it's outsides by providing a mask or a test function.

example of what would be cool if doable:

Image = cv2.imread("SomeImage")
mask  = np.zeros(Image.shape)
cv2.circle(mask, (70, 70), 60, 255, -1)

kernel = np.ones((2, 2), np.uint8)
cv2.erode(Image, kernel, ignore=mask) # There is no such thing as an "ignore" parameter
0

There are 0 best solutions below