Function Repository Resource:

# ImageTakeAt

Get a part of an image at a specified position with specified dimensions

Contributed by: AMP
 ResourceFunction["ImageTakeAt"][image, center, dimensions] takes a part of the image around the specified center position up to the requested dimensions. ResourceFunction["ImageTakeAt"][image, center, dimensions, background] takes a part of the image with the given dimensions, padding with background as needed.

## Details

ResourceFunction["ImageTakeAt"][image, center, dimensions, background] uses ImagePad[subimage, background] to set the background color and pad the subimage.
Only for two odd-valued subimage dimensions, the image part will be exactly centered around specified center position. For an even-valued subimage dimensions, to avoid image content interpolation, the resulting subimage will be taken half a pixel upwards and/or to the left relative to the specified center.
ResourceFunction["ImageTakeAt"] currently only works for 2D images.

## Examples

### Basic Examples (5)

Get a test image of the moon:

 In[1]:=

Get a subimage:

 In[2]:=
 Out[2]=

Here, the size of the subimage is smaller than requested since its center was at the image’s border:

 In[3]:=
 Out[3]=

Take an image part and pad it with the specified background color to obtain the requested dimensions:

 In[4]:=
 Out[4]=

Verify that the results have the expected sizes:

 In[5]:=
 Out[5]=

### Scope (5)

Define a pattern image:

 In[6]:=

Show the pattern image with Axes for pixel coordinates:

 In[7]:=
 Out[7]=

Take a 3×3 subimage centered at {3,3}:

 In[8]:=
 Out[9]=

Take a 2×2 subimage at {3,3}. It will be extracted half a pixel upwards and to the left of the specified center at {2.5, 3.5}:

 In[10]:=
 Out[11]=

Take a 4×3 subimage at {3,3}. To avoid image interpolation, it will be extracted half a pixel to the left of the specified center at {2.5, 3}:

 In[12]:=
 Out[13]=

### Applications (6)

ImageCorrelate can be used to locate an extracted subimage. Define a test image of a mandrill:

 In[14]:=

Get the mandrill's eye as a subimage:

 In[15]:=
 Out[15]=

Validate its dimensions:

 In[16]:=
 Out[16]=

Find the location of the eye using ImageCorrelate:

 In[17]:=
 Out[17]=

Verify its location:

 In[18]:=
 Out[18]=

Show the match with HighlightImage:

 In[19]:=
 Out[19]=

## Publisher

Asmus Meyer-Plath

## Version History

• 1.0.0 – 25 January 2023