I want to apply Gaussian blur on pixel coordinates of a polygon inside a larger image and then do something with the blurred polygon on the same coordinates. The draw polygon function that exists in skimage
gives me the coordinates directly of the image and not a mask. I ideally want to apply the filter on the mask itself but the draw polygon
function doesn't get me the mask.
img = np.zeros((10, 10), dtype=np.uint8)
r = np.array([1, 2, 8, 1])
c = np.array([1, 7, 4, 1])
rr, cc = polygon(r, c)
# Apply Gaussian blur here on the locations specified by the polygon
img[rr, cc] = 1 # or do something else on the blurred positions.
I can't obviously run the Gaussian blur on the image first because if I ran the Gaussian blur on rr, cc
, I would get decimal values and won't be able to access the same polygon by indexing. How do I solve the problem?
Here's how I solved it.
mask = np.zeros_like(img)
mask[rr, cc] = 1 # or anything else on the blurred positions
mask = filters.gaussian(mask, sigma=3)