How to apply a grid of rectangles and extract them as separate images

Hello everyone! I am trying to apply a grid composed by 15 rectangles (5 columns, 3 rows, spacing 7) on my tif images so that it is centred. All these rectangles would need to be cut out of the original image in a defined order (let’s say row by row, from left to right) and saved with serial numbers (from 01) in a folder named “ordered” (thus, different from the one I get the original image from). Is it actually possible to design such a code for a macro? So far I have been unable to…


Perhaps this older thread contains the tools/scripts you need (just read through the whole thing…):

You can adapt things as you need… but should be enough info in there to get you started. If you have more specific questions - just ask. We are here to help.


Yes, this is possible but I fear you will need a little ImageJ-macro.

Define a suitable rectangular selection and a start position which will result in the first image. With the selection in this first position simply do a copy which results in a new image of just the selected area of your original image. Name this cut-out image, e.g. by appending an number to the original image name. Then move the rectangular selection e.g. to the right by its width etc. When you’ve reached the end of the row, start the second row with positioning the rectangular selection below the very first position etc.

This can be done by using two loops, one for the horizontal shifts and one for the vertical shifts. Not very complicated and macro coding is really easy!

Good luck