Home > Back-end >  how to get the pixels of an image upto a particular radius in python
how to get the pixels of an image upto a particular radius in python

Time:10-23

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
  • Related