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)
| 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. */ |