package ij.plugin;
import ij.*;
import ij.gui.GenericDialog;
import ij.process.*;
import ij.measure.Calibration;
/** This plugin implements the Image/Stacks/Tools/Grouped Z Project command. */
public class GroupedZProjector implements PlugIn {
private static int method = ZProjector.AVG_METHOD;
private int groupSize;
public void run(String arg) {
ImagePlus imp = IJ.getImage();
int size = imp.getStackSize();
if (size==1) {
IJ.error("Z Project", "This command requires a stack");
return;
}
if (imp.isHyperStack()) {
new ZProjector().run("");
return;
}
if (!showDialog(imp))
return;
ImagePlus imp2 = groupZProject(imp, method, groupSize);
imp2.setCalibration(imp.getCalibration());
Calibration cal = imp2.getCalibration();
cal.pixelDepth *= groupSize;
if (imp!=null)
imp2.show();
}
public ImagePlus groupZProject(ImagePlus imp, int method, int groupSize) {
if (method<0 || method>=ZProjector.METHODS.length)
return null;
int[] dim = imp.getDimensions();
int projectedStackSize = imp.getStackSize()/groupSize;
imp.setDimensions(1, groupSize, projectedStackSize);
ZProjector zp = new ZProjector(imp);
zp.setMethod(method);
zp.setStartSlice(1);
zp.setStopSlice(groupSize);
zp.doHyperStackProjection(true);
imp.setDimensions(dim[2], dim[3], dim[4]);
ImagePlus zProjectorOutput = zp.getProjection();
int[] zProjectDim = zProjectorOutput.getDimensions();
for (int i=2; isize || (size%groupSize)!=0) {
IJ.error("ZProject", "Group size must divide evenly into the stack size.");
return false;
}
return true;
}
}
Ads help maintain this website.