1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/**
* This plugin, which implements the Image/Stacks/Plot XY Profile command,
* generates a stack of plots with the same vertical scale.
* Source image is a stack or hyperstack.
* Line or rectangle selection is required.
* @author Jerome Parent
*/
package ij.plugin;
import ij.*;
import ij.gui.*;
import java.awt.*;
public class StackPlotter implements PlugIn {
private int channel = 1;
private int slice = 1;
private int frame = 1;
private int frames = 1;
public void run(String arg) {
ImagePlus imp = IJ.getImage();
//Check if Roi is defined
if (imp.getRoi() == null) {
IJ.error("Stack Plotter", "Line or rectangular selection required");
return;
}
//Check if Image is a Stack
int dim = imp.getNDimensions();
if (dim < 3) {
IJ.error("Stack Plotter","This plugin requires a stack");
return;
}
//Get Stack size
int length = 0;
if (dim==3)
length = imp.getImageStackSize();
// Plot stack over frames information, improvement will be to select the dimension to plot over
boolean plotFrames = true;
if (dim>3) {
channel = imp.getChannel();
slice = imp.getSlice();
frame = imp.getFrame();
length = frames = imp.getNFrames();
if (dim==4 && length==1) {
plotFrames = false;
length = imp.getNSlices();
}
} else
slice = imp.getCurrentSlice();
//Get a profile plot for each frame in the stack
//Store min and max value of all Profile across the stack
ProfilePlot[] pPlot = new ProfilePlot[length];
double ymin = 0;
double ymax = 0;
for (int i=0; i<length; i++) {
if (dim == 3) imp.setPosition(i+1);
if (dim > 3) {
if (plotFrames)
imp.setPosition(channel,slice,i+1);
else
imp.setPosition(channel,i+1,frame);
}
pPlot[i] = new ProfilePlot(imp);
if (pPlot[i] == null) return;
if (pPlot[i].getMin() < ymin) ymin = pPlot[i].getMin();
if (pPlot[i].getMax() > ymax) ymax = pPlot[i].getMax();
}
//Save current Min and Max values of profile plot
double pp_min = ProfilePlot.getFixedMin();
double pp_max = ProfilePlot.getFixedMax();
//Set same Min Max values for all plots
ProfilePlot.setMinAndMax(ymin,ymax);
//Make a profile stack
Plot plot = pPlot[0].getPlot();
Dimension size = plot.getSize();
ImageStack stack = new ImageStack(size.width,size.height);
for (int i=0; i< length; i++) {
plot = pPlot[i].getPlot();
stack.addSlice(plot.getProcessor());
}
ImagePlus output = new ImagePlus("Profile Plots",stack);
output.show();
output.setSlice(slice);
if (dim==3) imp.setPosition(slice);
if (dim>3) imp.setPosition(channel,slice,frame);
//reset profile plot Min and May
ProfilePlot.setMinAndMax(pp_min,pp_max);
}
}
|