Creation of a test image with 2d circular shaped objects having Gaussian brightness distribution profile
One way to proceed is to make an image that contains a single white pixel at each desired center point and then to convolve the small particle with the image:
particle = Import["http://i.stack.imgur.com/gi6U1.png"];
randomCoords = Array[{RandomReal[], RandomReal[]} &, 20];
img = Image[Array[0 &, {400, 400}]];
points = ReplacePixelValue[img, randomCoords*400 -> 1];
ImageConvolve[points, particle]
Update:
Belisarius suggested in comments a method using image processing (i.e. GaussianFilter
) to generate the image. I'd modify his approach to use RandomChoice
to generate the initial spots, which seems more direct to me:
img = Image@RandomChoice[{10000, 1} -> {0, 1}, {400, 400}];
ImageAdjust@GaussianFilter[img, 15]
I am going to create your object as the PDF of a binormal distribution with means equal to the $(x,y)$ position of the object, and equal standard deviations (to give a circular particle image) whose values (8) have been chosen to be pleasing with an image size of 400 units (of course, adjust to taste).
Clear[object, positions, imagefunction]
SeedRandom[7]
object[px_, py_] = PDF[BinormalDistribution[{px, py}, {8, 8}, 0], {x, y}];
Now generate some random positions, apply the object function to generate those objects, then sum all those distribution PDF to obtain a parametric description of a 3D surface:
positions = RandomInteger[{1, 400}, {20, 2}];
imagefunction = Plus @@ object @@@ positions;
Finally use DensityPlot
to slice that surface and obtain your image:
DensityPlot[imagefunction, {x, 1, 400}, {y, 1, 400},
PlotPoints -> 150, ColorFunction -> GrayLevel,
Frame -> None, PlotRange -> All
]
To get an actual image, rather than a Graphics
object, use e.g. Rasterize
, Export
...:
Rasterize[%]
ImageAdjust
won't work well when there are superpositions,
SeedRandom[42];
n = 400;
gf[i_Image] := GaussianFilter[i, {n/20, n/80}]
ImageAdjust [ ri= gf@RandomImage[BernoulliDistribution[50/n^2], {n, n}]]
Use Clip/Rescale instead:
resc = Max@ImageData@gf@Image@SparseArray[{n/2, n/2} -> 1, {n, n}];
Image@Clip@Rescale[ImageData@ri, {0, resc}]
(* or, mostly the same but slower*)
ImageApply[Clip@Rescale[#, {0, resc}] &, ri]