Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get a part of an image at a specified position with specified dimensions
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. |
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]= | ![]() |
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]= | ![]() |
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]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License