I'm trying to get the pixels of a particular point up to a radius as the circle in the image below. I know this is possible with contours, but contours are too slow and I need to get those pixels in real-time
image: https://i.stack.imgur.com/GVe9H.png
thanks in advance
CodePudding user response:
You can exploit the numpy meshgrid
function together with some geometry:
h, w = # img size
y, x = # point location
xx, yy = np.meshgrid(np.linspace(0, h-1, h), np.linspace(0, w-1, w))
mask = (xx-x)**2 (yy-y)**2 < radius**2
Then, to get the image pixels:
extracted_image = image * mask