# Returning a bounding disk or box centered on a coordinate in a 2D image

Provided a coordinate $c_k$ in a two-dimensional image, how can I return all of the pixels in a bounding disk or rectangle centered on $c_k$ of some specified dimension $d$?

Update: Hat tip to Kuba for recommending PixelValue and Sjoerd C. de Vries for recommending ImageData. However, considering the case of the bounding box, is it possible to return the pixels using:

PixelValue[image,
{Subscript[x, min];;Subscript[x, max],Subscript[y, min];;Subscript[y, max]}]


In the form of a matrix rather than a 1-dimensional array?

-
Take a look at PixelValue. – Kuba Jun 25 '13 at 21:27
Or ImageData. – Sjoerd C. de Vries Jun 25 '13 at 21:32
@Kuba Terrific, thanks! – Bob Jun 25 '13 at 21:33
About returning a matrix: how would a circular matrix look like? – Sjoerd C. de Vries Jun 25 '13 at 22:01
@SjoerdC.deVries Apologies, I meant for the bounding box with some $x_{min}$ to $x_{max}$ and $y_{min}$ to $y_{max}$ specified with the indicated command. – Bob Jun 25 '13 at 22:02

In order to return a square two-dimensional matrix of pixels with edge dimension $2*k+1$ centered at some point $(c_x,c_y)$ - i.e. we grab $k$ pixels to the right, to the left, above, and below $(c_x,c_y)$ - we can write:

data = PixelValue[image, {cx - k ;; cx + k, cy - k ;; cy + k}];
TempArray = Partition[data, 2*k + 1];


This can easily be generalized to a rectangular matrix with edge dimensions $k_1 \times k_2$ by writing:

data = PixelValue[image, {cx - k1 ;; cx + k1, cy - k2 ;; cy + k2}];
TempArray = Partition[data, 2*k1 + 1];


One can also trivially change the offset by slightly modifying the above approach.

-