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

Method cropAndSave

ij/src/main/java/ij/ImagePlus.java:2740–2757  ·  view source on GitHub ↗

Saves the contents of the ROIs in this overlay as separate images, where 'directory' is the directory path and 'format' is "tif", "png" or "jpg". Set 'format' to "show" and the images will be displayed in a stack and not saved.

(Roi[] rois, String directory, String format)

Source from the content-addressed store, hash-verified

2738 * and not saved.
2739 */
2740 public void cropAndSave(Roi[] rois, String directory, String format) {
2741 ImagePlus[] images = crop(rois);
2742 if (format==null) format = "";
2743 if (format.contains("show")) {
2744 ImageStack stack = ImageStack.create(images);
2745 new ImagePlus("CROPPED_"+getTitle(),stack).show();
2746 return;
2747 }
2748 String fileFormat = "tif";
2749 if (format.contains("png")) fileFormat = "png";
2750 if (format.contains("jpg")) fileFormat = "jpg";
2751 for (int i=0; i<images.length; i++) {
2752 Rectangle bounds = rois[i].getBounds();
2753 String title = IJ.pad(bounds.x,4)+"-"+IJ.pad(bounds.y,4);
2754 String path = directory + title + "." + fileFormat;
2755 IJ.saveAs(images[i], fileFormat, path);
2756 }
2757 }
2758
2759 /** Returns a new ImagePlus with this image's attributes
2760 (e.g. spatial scale), but no image. */

Callers 1

doOverlayMethod · 0.95

Calls 8

cropMethod · 0.95
createMethod · 0.95
getTitleMethod · 0.95
padMethod · 0.95
saveAsMethod · 0.95
getBoundsMethod · 0.65
containsMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected