# Reproducing Image Patterns with Mathematica

Surfing on the net I stared at this pattern. It´s a bamboo steam, and it´s awesome. I'm new to Mathematica so I'm a little lost, I'd like to try to reproduce this pattern, of course in a very simplified manner. Does anyone have any tips on how I could start it. Thanks..

-
This reminds me of the question How can I pack circles of different sizes into a spiral?. Your pattern is quite different, but using circles in a hierarchical way might be a starting point. –  Jens Aug 3 '12 at 3:57
–  belisarius Aug 3 '12 at 5:18
It looks like there are some fractal pattern in your bamboo. btw what exactly do you mean by reproducing? It might need some more accurate clarification. –  Silvia Aug 3 '12 at 9:46
You might want to look into Apollonian gaskets. –  Ｊ. Ｍ. Aug 3 '12 at 10:43

Here's an approach based on generating a set of points (the centres of the voids) and using a DistanceTransform:

i=Image[Graphics[{White,Disk[{0,0},1],Black,
Point@Flatten[Table[r^(1/4) {Sin[t],Cos[t]},{r,0.001,1,0.1},{t,0.001,2Pi,0.025/r}],1],
Point@Table[RandomReal[{0.2,1}]Through[{Sin,Cos}[RandomReal[{0,2Pi}]]],{1000}]},
Background->Black],ImageSize->500];

i2=ImageMultiply[DistanceTransform[i],0.1];

i3=ColorNegate@GaussianFilter[Binarize[i2,1.0],4];



-
+1 I like this a lot –  Ajasja Aug 3 '12 at 13:13
+1 Very nice image –  Vitaliy Kaurov Aug 3 '12 at 15:27
+1 Excellent code! –  R Hall Aug 4 '12 at 13:42

I'm not sure exactly what you mean by recreate using Mathematica but here is a quick image process/computational geometry based method.

I imported the image:

image = Import["http://www.quorumtech.com/media/image_gallery/cache/Bamboo_stem.jpg"]


Ran an edge detection filter and then isolated the individual components

m = MorphologicalComponents[EdgeDetect[image]]; m // Colorize


Then determine the centroid of the components

points = ComponentMeasurements[m, "Centroid"][[All, 2]];


Then compute a voronoi diagram of the points (you could alter these points to adjust the structure in mathematica)

Needs["ComputationalGeometry"];
DiagramPlot[points, TrimPoints -> 500, LabelPoints -> False]


-

Maybe this code that I wrote long time ago (so, the inefficiency is included for free) might be what you're looking for.

circleIntersect[x1_, y1_, r1_, x2_, y2_, r2_] := Module[
{dx, dy, distance},
dx = x1 - x2;
dy = y1 - y2;
distance = Sqrt[dx*dx + dy*dy];
r1 + r2 >= distance
]

theCircle = {{0, 0}, 50};

crit[x1_, y1_, r1_] := Module[{dist},
dist = Sqrt[x1*x1 + y1*y1] + r1;
dist >= theCircle[[2]]
]

newCircle0[] := {{RandomReal[{-50, 50}], RandomReal[{-50, 50}]},
RandomReal[{0.5, 4}]};

newCircle[] := Module[{temp},
While[
temp = newCircle0[];
crit[temp[[1, 1]], temp[[1, 2]], temp[[2]]]
];
temp]

circleList = {newCircle[]};
noList = {};

For[j = 0, j < 10000, j++,
c = newCircle[];
r = Table[
circleIntersect[c[[1, 1]], c[[1, 2]], c[[2]],
circleList[[i, 1, 1]], circleList[[i, 1, 2]],
circleList[[i, 2]]], {i, Length[circleList]}];
If[Count[r, True] > 0,
noList = Append[noList, c],
circleList = Append[circleList, c]];
]
circleList;

Show[{Graphics[Circle[{0, 0}, 50]],
Graphics[
Table[Circle[{circleList[[i, 1, 1]], circleList[[i, 1, 2]]},
circleList[[i, 2]]], {i, Length[circleList]}]]}]
`

Higher is the value of j in the for-loop, more densely packed will be the circles (and more time it will take).

-