Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create an image by tessellating many copies of a source image into a template
ResourceFunction["TessellateGraphics"][graphic,mask] creates an image using many copies of graphic placed using the binary image mask as a guide. |
"MinInsetSize" | 4 | the smallest size of inset image measured in template image pixels |
"Mask" | Automatic | the shape to eliminate from the template |
"MaskScaling" | 1 | the magnification of the mask to eliminate from the template |
"InsetScaling" | 0.98 | the magnification of the inset image to place in the output |
"MaxIterations" | 6 | the number of times to search for remaining space to insert images |
Where the mask is Graphics, white areas are to be filled and black areas and Background are not. For example, fill a half Disk with disks:
In[1]:= |
Out[1]= |
Where the mask is an Image, areas of white pixels are to be filled and black areas are not. For example, create an image of a car using disks:
In[2]:= |
Out[2]= |
The inset contents can be a Wolfram Language Image, Graphics or Graphics3D:
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
If the inset contents is an image without an alpha channel, the whole image will be used:
In[5]:= |
Out[5]= |
To use nonrectangular images, set the alpha channel to modify their shape:
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
RemoveBackground can be useful preprocessing for an inset Image:
In[8]:= |
Out[8]= |
TessellateGraphics attempts to generate an inset image mask automatically from the inset image. No further inset images will be placed in masked areas. For images, the alpha channel is used to decide the mask. For Graphics and Graphics3D expressions, all primitives are used regardless of color. If the inset graphic contains transparent contents, this may cause inset graphics within the inset graphics:
In[9]:= |
Out[9]= |
To prevent this, specify the option "Mask":
In[10]:= |
Out[10]= |
By default, the inset image is 2% smaller than the mask, leaving space around each image. Decreasing the value of "InsetScaling" will leave more space:
In[11]:= |
Out[11]= |
Increasing it will cause overlapping images:
In[12]:= |
Out[12]= |
TessellateGraphics recursively fills empty space with smaller inset images. Control the number of iterations with the "MaxIterations" option. The smallest graphic to be inset is controlled by the "MinInsetSize" option given in pixel sizes from the template image:
In[13]:= |
Out[13]= |
If the inset image has PlotRangePadding, ImagePadding or a PlotRange, it may not fill its bounding box:
In[14]:= |
Out[15]= |
Use "InsetScaling" to partially compensate:
In[16]:= |
Out[16]= |
This work is licensed under a Creative Commons Attribution 4.0 International License