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

Method crop

ij/src/main/java/ij/plugin/Duplicator.java:314–366  ·  view source on GitHub ↗

Returns a copy the current image or stack slice, cropped if there is a selection. @see ij.ImagePlus#crop @see ij.ImagePlus#crop(String)

(ImagePlus imp)

Source from the content-addressed store, hash-verified

312 * @see ij.ImagePlus#crop(String)
313 */
314 public ImagePlus crop(ImagePlus imp) {
315 if (imp.getNChannels()>1 && imp.getCompositeMode()==IJ.COMPOSITE) {
316 int z = imp.getSlice();
317 int t = imp.getFrame();
318 return run(imp, 1, imp.getNChannels(), z, z, t, t);
319 }
320 boolean hyperstack = imp.isHyperStack();
321 int displayMode = imp.isComposite()?imp.getDisplayMode():0;
322 ImageProcessor ip = imp.getProcessor();
323 ImageProcessor ip2 = ip.crop();
324 ImagePlus imp2 = imp.createImagePlus();
325 imp2.setProcessor("DUP_"+imp.getTitle(), ip2);
326 String info = (String)imp.getProperty("Info");
327 if (info!=null)
328 imp2.setProperty("Info", info);
329 imp2.setProperties(imp.getPropertiesAsArray());
330 if (imp.hasImageStack()) {
331 ImageStack stack = imp.getStack();
332 String label = stack.getSliceLabel(imp.getCurrentSlice());
333 if (label!=null) {
334 if (label.length()>250 && label.indexOf('\n')>0 && label.contains("0002,"))
335 imp2.setProperty("Info", label); // DICOM metadata
336 else
337 imp2.setProp("Slice_Label", label);
338 }
339 if (imp.isComposite()) {
340 LUT lut = ((CompositeImage)imp).getChannelLut();
341 if (displayMode==IJ.GRAYSCALE)
342 imp2.getProcessor().setColorModel(null);
343 else
344 imp2.getProcessor().setColorModel(lut);
345 }
346 } else {
347 String label = imp.getProp("Slice_Label");
348 if (label!=null)
349 imp2.setProp("Slice_Label", label);
350 }
351 Overlay overlay = imp.getOverlay();
352 if (overlay!=null && !imp.getHideOverlay()) {
353 Overlay overlay2 = overlay.crop(ip.getRoi());
354 if (imp.getStackSize()>1) {
355 if (hyperstack) {
356 int c = imp.getC();
357 int z = imp.getZ();
358 int t = imp.getT();
359 overlay2.crop(c,c,z,z,t,t);
360 } else
361 overlay2.crop(imp.getCurrentSlice(), imp.getCurrentSlice());
362 }
363 imp2.setOverlay(overlay2);
364 }
365 return imp2;
366 }
367
368 /** Returns a new stack containing a subrange of the specified stack. */
369 public ImagePlus run(ImagePlus imp, int firstSlice, int lastSlice) {

Callers 12

runMethod · 0.95
trimPlotMethod · 0.45
makeStackMethod · 0.45
straightenRotatedRectMethod · 0.45
cropOverlayMethod · 0.45
measureMethod · 0.45
doInverseTransformMethod · 0.45
swapQuadrantsMethod · 0.45
unpadMethod · 0.45
filterMethod · 0.45
tileMirrorMethod · 0.45
doInverseTransformMethod · 0.45

Calls 15

runMethod · 0.95
cropMethod · 0.95
setProcessorMethod · 0.95
setPropertyMethod · 0.95
setPropertiesMethod · 0.95
getSliceLabelMethod · 0.95
setPropMethod · 0.95
getProcessorMethod · 0.95
cropMethod · 0.95
getRoiMethod · 0.95
setOverlayMethod · 0.95
getCompositeModeMethod · 0.80

Tested by

no test coverage detected