Save the grid as seperate images on ImageJ

Hi all,
I’m using Grid plugin on ImageJ.After the grid selection is there any way to save all the areas as seperate images?

Thanks in advance for any information

Here is a adaptable script which creates rectangular ROI’s in the ROI Manager and saves the Manager ROI’s as individual images.
For a speedup remove the comment of setBatchMode(true) in the first line.

For the execution an image has to be loaded first.

Please adjust the values for your image and the save path location!

//setBatchMode(true);
x = 0; //the x-start coordinate
y = 0; //the y-start coordinate
width = 50; //the width of the rectangle
height = 50; //the height of the rectangle
spacing = 0; //spacing between the rectangles
numRow = 5; //how many rows
numCol = 5; //how many columns


/*Create the selections and add them to the ROI Manager!*/
for (i = 0; i < numRow; i++) {
    for (j = 0; j < numCol; j++) {
        xOffset = j * (width + spacing);
        yOffset = i * (height + spacing);
        /*Create a rectangular selection!*/
        makeRectangle(x + xOffset, y + yOffset, width, height);
        /*Add the selection to the ROI Manager!*/
        roiManager("Add");
    }
}
/*Show all selections in the image with (mouse) selectable labels!*/
roiManager("Show All with labels");
mainTitle=getTitle();
for (u = 0; u < roiManager("count"); ++u) {
    run("Duplicate...", "title=crop");
    roiManager("Select", u);
    run("Crop");
    saveAs("Tiff", "I:/GridSections/" + "Grid_Section_" + (u + 1) + ".tif");
    close();
    //Next round!
    selectWindow(mainTitle);
}

Exactly what I needed,works smoothly!
Thank you very much for your quick reply!

Best regards

Another quick question.How can I save the images with the specific names given in the region of interest?

Thanks a lot in advance.

You can use:

Roi.getName
Returns the selection name or an empty string if the selection does not have a name.

See:

https://imagej.nih.gov/ij/developer/macro/functions.html#R