0

I'm trying to solve a problem and am quite stuck on how to approach it. I have an image and I want to get all the pixels inside the circle area of interest.

The radius of the circle is 150 pixels and the centre point of the ROI is [256, 256].

I have tried to draw the circle on the image, but I couldn't find a way to access those pixels from that.

img = imread('Model/m1.png') * 255
row = size(img, 0) #imgWidth
col = size(img, 1) #imgHeight
px = row * col

circle = Circle((256, 256), 150, fill = False)
fig, ax = subplots()
ax.add_patch(circle)
imshow(img, cmap='gray')
show()

I was thinking maybe using the equation of a circle: (x - a)**2 + (y - b)**2 == r**2

But I'm not quite sure as wouldn't that only give you the pixels of the circle edge?

Any ideas or tips would be much appreciated.

MSmithy
  • 3
  • 1
  • "get the pixels" for what purpose? the purpose determines the representation of your circle. show what you mean with pictures. that's easiest. – Christoph Rackwitz Nov 30 '21 at 09:07
  • don't get distracted by literal answers to your question. they may be inefficient or not useful for what you *really* want to do. https://xyproblem.info/ – Christoph Rackwitz Nov 30 '21 at 09:09
  • The inequation (x-a)²+(y-b)²≤r² tells you the pixels on and inside. And for the row y, |x-a|≤√(r²-(y-b)²) tells you a range of x (provided the argument of the square root is non-negative). –  Nov 30 '21 at 09:20
  • The purpose is to analyse the pixel intensity with a histogram – MSmithy Nov 30 '21 at 09:28
  • Easy example here https://stackoverflow.com/a/59302130/2836621 – Mark Setchell Nov 30 '21 at 09:43
  • histogram... ok so the order of the pixels is irrelevant. good. many approaches. I'd calculate a mask (draw a filled circle into a "grayscale" (single channel uint8 or bool) numpy array, there's your mask), use the mask as an index into the numpy array to get those pixels, then feed into whatever histogram function you like. – Christoph Rackwitz Nov 30 '21 at 10:52

1 Answers1

0

Inequality (x - a)**2 + (y - b)**2 <= r**2 allows to walk through all pixels inside circle.

In practice you can scan Y-coordinates from b-r to b+r and walk through horizontal lines of corresponding X-range a - sqrt(r**2 - (y-b)**2) .. a + sqrt(r**2 - (y-b)**2)

MBo
  • 77,366
  • 5
  • 53
  • 86