# Challenge: Speeding up MaxDetect for application in 3D blob detection

In image segmentation it is a common problem that objects appear clustered and are therefore undistinguishable from each other when using simple algorithms. Based on this post I obtained efficient ways to tackle the problem based on fast 3D distance transformation (DistanceTransform3D) and the usage of the Mathematica built-in function MaxDetect. For details please have a look at the answer of UDB in the post. Consider two simple functions to generate a test Image3D containing sphere-like objects:

generateRandomObject3D[dim_, min_, max_] := Block[
{rdDim, rd, v, s1, s2},
rdDim = {RandomInteger[{min, max}], RandomInteger[{min, max}],
RandomInteger[{min, max}]};
rd = DiskMatrix[rdDim];
v = dim - 2 # - 1 & /@ rdDim;
s1 = # - RandomInteger[{1, #}] & /@ v; s2 = v - s1;
];

generateRandomImage3D[dim_, min_, max_, objNum_] := Block[
{},
Image3D[
Plus @@ Table[generateRandomObject3D[dim, min, max], {objNum}]]
];

objects=generateRandomImage3D[64, 5, 5, 15];
colComps=Colorize@MorphologicalComponents@objects;


Now we can identify the locations of the potentially clustered objects using a 3D distance transformation followed by MaxDetect.

AbsoluteTiming[MaxDetect[ImageAdjust@DistanceTransform3D[rand], 0.1]]


{1.339987, }

As you can see this operation already takes more than one second. If I check for the runtime of the individual steps, DistanceTransform3D needs about 1/4 of the time.

Is there a faster way of doing this? The images I need to apply the algorithm to are much larger. Therefore, efficiency and runtime plays an important role in this case.