Clear outside image to contain a moving ROI on a stack of 2000+ images


I have several stacks each with great than 2000 images on which there is a certain region of interest that I want to be the only portion of the image present. The problem is that the ROI is moving slightly with each successive image so I can’t just select that portion of the image I want and clear outside to all. I have been using Ctrl+0 with a macro that advances the image each time I clear outside and after every ~150 images I have to shift the selection area to include the ROI.

Is there a way for me to somehow have the selection area move with each successive image (tracking the ROI) without me having to manually move it?


If you know the ROI positions than you can apply a simple macro to move the ROI. Here an example with the ROI Manager (moves the ROI 20px each 5th slice) which you can easily extend to your purpose:

run("MRI Stack (528K)");
makeRectangle(23, 68, 33, 31);
dx = 20;
dy = 20;
for ( i=1 ; i <= nSlices; i++) {
    roiManager('select', 0);
    getSelectionBounds(x, y, w, h);
    setSelectionLocation(x+dx, y+dy);

Another way to track particles automatically would be to use a great tracking plugin like TrackMate:

If you have a simple case with one region you could also use the Particle Analysis of ImageJ to crop the ROI in each frame by applying the analysis on the whole stack.

1 Like