File: StackReverser.java

package info (click to toggle)
imagej 1.46a-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: java: 89,778; sh: 311; xml: 51; makefile: 6
file content (32 lines) | stat: -rw-r--r-- 774 bytes parent folder | download
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
package ij.plugin;
import ij.*;
import ij.process.*;

/** Implements the Image/Transform/Flip Z command. */
public class StackReverser implements PlugIn {
	
	public void run(String arg) {
		ImagePlus imp = IJ.getImage();
		if (imp.getStackSize()==1) {
			IJ.error("Flip Z", "This command requires a stack");
			return;
		}
		if (imp.isHyperStack()) {
			IJ.error("Flip Z", "This command does not currently work with hyperstacks.");
			return;
		}
		flipStack(imp);
	}
	
	public void flipStack(ImagePlus imp) {
		ImageStack stack = imp.getStack();
 		ImageStack stack2 = imp.createEmptyStack();
 		int n;
		while ((n=stack.getSize())>0) { 
			stack2.addSlice(stack.getSliceLabel(n), stack.getProcessor(n));
			stack.deleteLastSlice();
		}
		imp.setStack(null, stack2);
	}

}