1

I have 12 images. I am processing with ImageJ/FIJI. Then I made grid (using Analyze -> Tools -> Grid) of size 2923779 ( i.e. Area per point __ pixels ^2) for all images uniformly. It looks like this:

enter image description here

What I want to do is to crop the each of the image above according to every element of the grid and save every crop as a file. How can I do that?

One of the file above can be downloaded here (160MB).

neversaint
  • 60,904
  • 137
  • 310
  • 477

1 Answers1

2

You have to understand the code of grid.java here to do what you want. In a macro :

dir = getDirectory("the directory with all your files");
files = getFileList(dir);
out = getDirectory ("Select output directory");
number = lengthOf(files); // normally 12 in your case
i=0;
while (i < number) {
    // write a function to extract the x and y coordinates, the width and the height of each rectangle of your grid. For that, you have to understand the code of grid.java to understand how you can have the coordinates of each rectangle.
    listcoordinates = yourfunction(files[i], 2923779);// return a vector of (x0, y0, width0, height0, x1, y1, etc...) => x= x coordinate on the top left of the square, y= y coordinate on the top left of the square
    for(j=0; j<lengthOf(listcoordinates); j+4) //foreach coordinate that you extract
     {
        makeRectangle(listcoordinates[j], listcoordinates[j+1], listcoordinates[j+2], listcoordinates[j+3]);
        run("Duplicate...", "title=blabla"+ i + j +".tif");
        saveAs("Tiff", out+ "blabla" + i + j + ".tif");
     }
}

Good luck ;)

EaudeRoche
  • 207
  • 4
  • 19