MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / createNewStack

Method createNewStack

ij/src/main/java/ij/plugin/Scaler.java:103–168  ·  view source on GitHub ↗
(ImagePlus imp, ImageProcessor ip, int newWidth, int newHeight, int newDepth)

Source from the content-addressed store, hash-verified

101 }
102
103 private ImagePlus createNewStack(ImagePlus imp, ImageProcessor ip, int newWidth, int newHeight, int newDepth) {
104 int nSlices = imp.getStackSize();
105 int w=imp.getWidth(), h=imp.getHeight();
106 ImagePlus imp2 = imp.createImagePlus();
107 Rectangle r = ip.getRoi();
108 boolean crop = r.width!=imp.getWidth() || r.height!=imp.getHeight();
109 ImageStack stack1 = imp.getStack();
110 ImageStack stack2 = new ImageStack(newWidth, newHeight);
111 boolean virtualStack = stack1.isVirtual();
112 double min = imp.getDisplayRangeMin();
113 double max = imp.getDisplayRangeMax();
114 ImageProcessor ip1, ip2;
115 int method = interpolationMethod;
116 if (w==1 || h==1)
117 method = ImageProcessor.NONE;
118 for (int i=1; i<=nSlices; i++) {
119 IJ.showStatus("Scale: " + i + "/" + nSlices);
120 ip1 = stack1.getProcessor(i);
121 String label = stack1.getSliceLabel(i);
122 if (crop) {
123 ip1.setRoi(r);
124 ip1 = ip1.crop();
125 }
126 ip1.setInterpolationMethod(method);
127 ip2 = ip1.resize(newWidth, newHeight, averageWhenDownsizing);
128 if (ip2!=null)
129 stack2.addSlice(label, ip2);
130 IJ.showProgress(i, nSlices);
131 }
132 imp2.setStack(title, stack2);
133 if (virtualStack)
134 imp2.setDisplayRange(min, max);
135 Calibration cal = imp2.getCalibration();
136 if (cal.scaled()) {
137 cal.pixelWidth *= 1.0/xscale;
138 cal.pixelHeight *= 1.0/yscale;
139 }
140 cal.xOrigin *= xscale;
141 cal.yOrigin *= yscale;
142 Overlay overlay = imp.getOverlay();
143 if (overlay!=null && !imp.getHideOverlay() && !doZScaling) {
144 overlay = overlay.duplicate();
145 Rectangle roi = imp.getProcessor().getRoi();
146 if (roi!=null)
147 overlay = overlay.crop(ip.getRoi());
148 imp2.setOverlay(overlay.scale(xscale, yscale));
149 }
150 IJ.showProgress(1.0);
151 int[] dim = imp.getDimensions();
152 imp2.setDimensions(dim[2], dim[3], dim[4]);
153 if (imp.isComposite()) {
154 imp2 = new CompositeImage(imp2, ((CompositeImage)imp).getMode());
155 ((CompositeImage)imp2).copyLuts(imp);
156 }
157 if (imp.isHyperStack())
158 imp2.setOpenAsHyperStack(true);
159 if (doZScaling) {
160 double oldSize = imp2.getStackSize();

Callers 2

runMethod · 0.95
resizeMethod · 0.95

Calls 15

isVirtualMethod · 0.95
showStatusMethod · 0.95
getProcessorMethod · 0.95
getSliceLabelMethod · 0.95
setRoiMethod · 0.95
cropMethod · 0.95
resizeMethod · 0.95
addSliceMethod · 0.95
showProgressMethod · 0.95
setStackMethod · 0.95
setDisplayRangeMethod · 0.95

Tested by

no test coverage detected