Implements the Image/HyperStacks/Reduce Dimensionality command.
| 11 | |
| 12 | /** Implements the Image/HyperStacks/Reduce Dimensionality command. */ |
| 13 | public class HyperStackReducer implements PlugIn, DialogListener { |
| 14 | ImagePlus imp; |
| 15 | int channels1, slices1, frames1; |
| 16 | int channels2, slices2, frames2; |
| 17 | double imageSize; |
| 18 | static boolean keep = true; |
| 19 | |
| 20 | /** Default constructor */ |
| 21 | public HyperStackReducer() { |
| 22 | } |
| 23 | |
| 24 | /** Constructs a HyperStackReducer using the specified source image. */ |
| 25 | public HyperStackReducer(ImagePlus imp) { |
| 26 | this.imp = imp; |
| 27 | this.channels1 = this.channels2 = imp.getNChannels(); |
| 28 | this.slices1 = this.slices2 = imp.getNSlices(); |
| 29 | this.frames1 = this.frames2 = imp.getNFrames(); |
| 30 | } |
| 31 | |
| 32 | public void run(String arg) { |
| 33 | //IJ.log("HyperStackReducer-1"); |
| 34 | imp = IJ.getImage(); |
| 35 | if (!imp.isHyperStack() && imp.getNChannels()==1) { |
| 36 | IJ.error("Reducer", "HyperStack required"); |
| 37 | return; |
| 38 | } |
| 39 | int width = imp.getWidth(); |
| 40 | int height = imp.getHeight(); |
| 41 | imageSize = width*height*imp.getBytesPerPixel()/(1024.0*1024.0); |
| 42 | channels1 = channels2 = imp.getNChannels(); |
| 43 | slices1 = slices2 = imp.getNSlices(); |
| 44 | frames1 = frames2 = imp.getNFrames(); |
| 45 | int z0 = imp.getSlice(); |
| 46 | int t0 = imp.getFrame(); |
| 47 | if (!showDialog()) |
| 48 | return; |
| 49 | //IJ.log("HyperStackReducer-2: "+keep+" "+channels2+" "+slices2+" "+frames2); |
| 50 | String title2 = keep?WindowManager.getUniqueName(imp.getTitle()):imp.getTitle(); |
| 51 | ImagePlus imp2 = null; |
| 52 | if (keep) { |
| 53 | imp2 = IJ.createImage(title2, imp.getBitDepth()+"-bit", width, height, channels2*slices2*frames2); |
| 54 | if (imp2==null) return; |
| 55 | imp2.setDimensions(channels2, slices2, frames2); |
| 56 | imp2.setCalibration(imp.getCalibration()); |
| 57 | imp2.setOpenAsHyperStack(true); |
| 58 | } else |
| 59 | imp2 = imp.createHyperStack(title2, channels2, slices2, frames2, imp.getBitDepth()); |
| 60 | imp2.setProperty("Info", (String)imp.getProperty("Info")); |
| 61 | imp2.setProperties(imp.getPropertiesAsArray()); |
| 62 | reduce(imp2); |
| 63 | if (channels2>1 && channels2==imp.getNChannels() && imp.isComposite()) { |
| 64 | int mode = ((CompositeImage)imp).getMode(); |
| 65 | imp2 = new CompositeImage(imp2, mode); |
| 66 | ((CompositeImage)imp2).copyLuts(imp); |
| 67 | } else { |
| 68 | imp2.setDisplayRange(imp.getDisplayRangeMin(), imp.getDisplayRangeMax()); |
| 69 | if (imp.isComposite() && ((CompositeImage)imp).getMode()==IJ.GRAYSCALE) |
| 70 | IJ.run(imp2, "Grays", ""); |
nothing calls this directly
no outgoing calls
no test coverage detected