Wolfram Research

Function Repository Resource:

DigitalCirclism

Source Notebook

Generate circle packings covering a picture

Contributed by: Christophe Favergeon

ResourceFunction["DigitalCirclism"][image]

compute a circle covering of an image.

Details and Options

ResourceFunction["DigitalCirclism"] can use the following options:
"TimeConstraint" 180 the maximum number of seconds allowed for the computation
"Pad" 0.0 the padding between the circles
"DrawingFunction" Automatic how to draw and style the circles
"CompositionFunction" Automatic how to compose the image and the circles
"RawResult" False whether to return an image or the list of circles
"Radii" {50,20,10,5,3,2} the list of radii used to shrink the radii of the covering
If the maximum number of seconds have been reached, a result will be returned but it may not contain all the circles.
The "DrawingFunction" option accepts a function of the form drawfun[image,centers,radii].
The "CompositionFunction" option accepts a function of the form compfun[image, graphics] where graphics contains the circle covering.
When "RawResult" is True, the function returns a pair of lists: list of centers and list of radii.
The option "Radii" is used to filter the circles from the picture. The algorithm will try to place the biggest circles first. When a circle cannot be placed because it overlaps with other circles, then it will be reduced to the next radius found in the "Radii" list. In practice, you won't often see a big difference in the resulting image if you change this list.
The "Radii" list should be ordered in decreasing order with the smallest radius last.

Examples

Basic Examples (1) 

Generate a circle covering for a sample image:

In[1]:=
ResourceFunction["DigitalCirclism"][
 ExampleData[{"TestImage", "Girl3"}]]
Out[1]=

Options (2) 

DrawingFunction (1) 

We can replace the disks by regular polygons or any other shapes we'd like to use. The opacity can be changed. A "DrawingFunction" option is provided for that purpose:

In[2]:=
ResourceFunction["DigitalCirclism"][
 ExampleData[{"TestImage", "Girl3"}], "DrawingFunction" -> ({RGBColor @@ ImageValue[#1, Floor[#2]], Opacity[0.5], EdgeForm[Red], Translate[RegularPolygon[#3, 7], #2]} &)]
Out[2]=

CompositionFunction (1) 

The circle covering and the image can be composed in different ways. A "CompositionFunction" is provided for that purpose:

In[3]:=
ResourceFunction["DigitalCirclism"][
 ExampleData[{"TestImage", "Girl3"}], "CompositionFunction" -> (Show[#1, #2] &)]
Out[3]=

Properties and Relations (3) 

Retrieve an image:

In[4]:=
img = ResourceData["Sample Image: White Dog on a Beach"]
Out[4]=

Compute the digital circlism directly:

In[5]:=
raw = ResourceFunction["DigitalCirclism"][img, "RawResult" -> True];
Short /@ raw
Out[5]=

Show the circles omitting the largest three:

In[6]:=
Graphics[MapThread[Circle[#1, #2] &, #[[4 ;;]] & /@ raw]]
Out[6]=

Resource History

Related Resources

License Information