# 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 has settled 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. – J. M. 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).

-

You could think of this as an inverse cellular automaton problem, where the goal is to find a cellular automaton that generates the (type of) pattern that you showed. It might be worth having a look at Cellular Automata, Theory and Experiment, Edited by Howard Gutowitz - http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=4479 - where the description says:

"The inverse problem, an area of study gaining prominence particularly in the natural sciences, involves designing rules that possess specified properties or perform specified task. A long-term goal is to develop a set of techniques that can find a rule or set of rules that can reproduce quantitative observations of a physical system. Studies of the inverse problem take up the organization and structure of the set of automata, in particular the parameterization of the space of cellular automata. Optimization and learning techniques, like the genetic algorithm and adaptive stochastic cellular automata are applied to find cellular automaton rules that model such physical phenomena as crystal growth or perform such adaptive-learning tasks as balancing an inverted pole."

-
It would be nice if you could provide an example of an automaton generating something similar. Meta-comment: Our tag system usually indicates what kind of answer is expected. We have a tag reference-request that is used when the question should be answered by providing pointers to literature, etc. This is not an opinion about the relevance of your cite (which may cover the topic quite well), and it is only intended as guidance about what kind of answer the OP wants. In this case, the OP was "just browsing the Net", so probably he isn't going thru a long path to satisfy his curiosity. – belisarius has settled Aug 3 '12 at 13:07
Perhaps I should have read the OP's question more carefully - it's about a specific pattern rather than patterns in general, though the question's title is more general than specific which is what misled me. I'll aim to give self-contained answers in future. – Stephen Luttrell Aug 3 '12 at 13:47