Posted by
TimoT on
May 20, 2016; 11:58am
URL: http://imagej.273.s1.nabble.com/Macro-command-to-skipping-blank-slices-in-a-stack-tp5016477.html
Hey everybody!
I'm doing a track of a school of fish swimming in a net pen. I need to process 1 fps still frames produced by a multibeam sonar and have gotten quite far in the task, which with my very limited programming skills is beginning to feel like a bit of an ordeal.
The aim is to track the area variations of the school with convex hulls. At the moment I have been able to succesfully import my images (~250-400/experiment) as a stack, and wrote a macro to convert them to thresholded binary and apply convex hull by first making point selections by "Find Maxima". Everything is working as planned, except that some of the slices are blank due to fish migrating vertically to a blind spot. My macro makes the convex hull vectors fine, but the whole process ends when there'a blank slice (See attached image), so is there a way to tell ImageJ to skip slices with nothing but 255 value pixels?
Thanks!

Here's what I've come up with so far.
run ("8-bit")
for (i = 1;i<=nSlices();i++){
run("Enhance Contrast...", "saturated=0.8 equalize");
run("Despeckle", "slice");
run("Gaussian Blur...", "sigma=0.50 slice");
makePolygon(449,565,599,26,557,29,432,534,363,526,242,25,203,28,344,564);
setForegroundColor(0, 0, 0);
run("Fill", "slice");
setAutoThreshold("Default");
//run("Threshold...");
setOption("BlackBackground", false);
run("Convert to Mask", "method=Default background=Default only");
run("Next Slice [>]");
}
run("Analyze Particles...", "size=23-999 pixel show=Masks include stack");
setSlice(1);
for (j=1;j<=nSlices();j++){
run("Create Selection");
run("Find Maxima...", "noise=10 output=[Point Selection] light");
run("Convex Hull");
run("Add Selection...");
run("Next Slice [>]");
}