<commit_before>from ij import IJ
from ij.plugin.frame import RoiManager

from io.scif.config import SCIFIOConfig
from io.scif.img import ImageRegion
from io.scif.img import ImgOpener
from io.scif.img import ImgSaver
from net.imagej.axis import Axes

import os

def main():
    # Get current image filename
    imp = IJ.getImage()
    f = imp.getOriginalFileInfo()
    
    if not f:
        IJ.showMessage('Source image needs to match a file on the system.')
        return

    # Iterate over all ROIs from ROI Manager
    rois = RoiManager.getInstance()

    if not rois:
        IJ.showMessage('No ROIs. Please use Analyze > Tools > ROI Manager...')
        return

    fname = os.path.join(f.directory, f.fileName)
    IJ.log('Image filename is %s' % fname)

    rois_array = rois.getRoisAsArray()
    for i, roi in enumerate(rois_array):
    
        crop_id = i +1
        IJ.log("Opening crop %i / %i" % (crop_id, len(rois_array)))
    
        # Get ROI bounds
        bounds = roi.getBounds()
        x = bounds.x
        y = bounds.y
        w = bounds.width
        h = bounds.height  
    
        # Import only cropped region of the image
        axes = [Axes.X, Axes.Y]
        ranges = ["%i-%i" % (x, x+w), "%i-%i" % (y, y+h)]
        config = SCIFIOConfig()
        config.imgOpenerSetRegion(ImageRegion(axes, ranges))
        
        opener = ImgOpener()
        imps = opener.openImgs(fname, config)
        imp = imps[0]
        
        # Get filename and basename of the current cropped image
        crop_basename = "crop%i_%s" % (crop_id, f.fileName)
        crop_fname = os.path.join(f.directory, crop_basename)
        IJ.log("Saving crop to %s" % crop_fname)
    
        # Save cropped image
        saver = ImgSaver()
        saver.saveImg(crop_fname, imp)
    
    IJ.log('Done')

main()<commit_msg>Disable save in Crop multi roi and show the image instead<commit_after>from ij import IJ
from ij.plugin.frame import RoiManager

from io.scif.config import SCIFIOConfig
from io.scif.img import ImageRegion
from io.scif.img import ImgOpener
from io.scif.img import ImgSaver
from net.imagej.axis import Axes
from net.imglib2.img.display.imagej import ImageJFunctions

import os

def main():
    # Get current image filename
    imp = IJ.getImage()
    f = imp.getOriginalFileInfo()
    
    if not f:
        IJ.showMessage('Source image needs to match a file on the system.')
        return

    # Iterate over all ROIs from ROI Manager
    rois = RoiManager.getInstance()

    if not rois:
        IJ.showMessage('No ROIs. Please use Analyze > Tools > ROI Manager...')
        return

    fname = os.path.join(f.directory, f.fileName)
    IJ.log('Image filename is %s' % fname)

    rois_array = rois.getRoisAsArray()
    for i, roi in enumerate(rois_array):
    
        crop_id = i +1
        IJ.log("Opening crop %i / %i" % (crop_id, len(rois_array)))
    
        # Get ROI bounds
        bounds = roi.getBounds()
        x = bounds.x
        y = bounds.y
        w = bounds.width
        h = bounds.height  
    
        # Import only cropped region of the image
        axes = [Axes.X, Axes.Y]
        ranges = ["%i-%i" % (x, x+w), "%i-%i" % (y, y+h)]
        config = SCIFIOConfig()
        config.imgOpenerSetRegion(ImageRegion(axes, ranges))
        
        opener = ImgOpener()
        imps = opener.openImgs(fname, config)
        imp = imps[0]
        
        # Get filename and basename of the current cropped image
        crop_basename = "crop%i_%s" % (crop_id, f.fileName)
        crop_fname = os.path.join(f.directory, crop_basename)
        imp.setName(crop_basename)
    
        # Save cropped image
        #IJ.log("Saving crop to %s" % crop_fname)
        #saver = ImgSaver()
        #saver.saveImg(crop_fname, imp)

        # Show cropped image
        ImageJFunctions.show(imp)
    
    IJ.log('Done')

main()
{'fraction_non_alphanumeric': 0.10406419880921564, 'fraction_numerical': 0.0012943308309603934, 'mean_word_length': 2.22, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4880089', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1306, 'n_words': 358}