Hey @Christian_Tischer,
this strategy is good, but a bit memory consumptive, because it allocates a new image with every iteration. You can measure/trace memory consumption using Ext.CLIJ_reportMemory().
. To spare memory in your case, you might at least put it a modulo operator:
numDilations = 10;
// init GPU
run("CLIJ Macro Extensions", "cl_device=");
Ext.CLIJ_clear();
// push an example image to the GPU and make a binary image from it
run("Blobs (25K)");
blobs = getTitle();
Ext.CLIJ_push(blobs);
image = "image";
Ext.CLIJ_automaticThreshold(blobs, image, "Otsu");
// iterative dilation
Ext.CLIJ_dilateSphere(image, "dilated0");
for (i = 0; i < numDilations; i++) {
Ext.CLIJ_dilateSphere("dilated"+(i) % 2, "dilated"+(i+1) % 2);
}
Ext.CLIJ_reportMemory();
Ext.CLIJ_pull("dilated"+ ((i+1) % 2));
Alternatively, you can use the maximum-filter which has radius parameters. In that way you can reduce the for loop to a single line. Note: Iterative exectution of dilateSphere results in a diamond neighborhood while maximumSphere leads to a sphere.
Furthermore, we realized during a discussion here on the forum, that iterative execution of such filters may be faster than a single maximum filter depending on radius and GPU-hardware. If you want to test CLIJ2 (alpha release, not fully tested yet
), there is a built-in iterative maximum filter using sphere and box neighborhoods alternating. The resulting neighborhood looks like an octagon. This might be the fastest approximation of a sphere available in CLIJ.
Let me know if this helps!
Cheers,
Robert