ROI Manager labelling after split

Hi all,

I am having issues using the ROI manager. I have a series of colonies on a Petri dish, and I have set up a series of ROIs to use on each plate as follows:

I then save these ROIs so that I can add them to a new image to measure the intensity of this new plate. As every plate is not imaged in the exact same position I have been Combining the ROIs, moving them, and then splitting them, all using the ROI manager. But the problem is that after I split the ROIs, FIJI re-labels them and changes their position:

Do you know if there is a way to keep the same labels and positioning of the ROIs after splitting?

I am sorry if this is a very basic question, but I really can’t figure it out. Thank you in advance to any one that gets back to me!

Hello Ruth -

I assume that you perform this workflow using the Fiji / ImageJ
gui, rather than a macro or script.

First, about the labels: When you combine the ROIs (I assume
that you run More >> OR (Combine) from the ROI Manager),
you create a (single) new ROI. This ROI has its own label (just
like other ROIs), but only one – it knows nothing about the labels
of the ROIs from which it was created. (We can discuss how
you could write a script to deal with this, if you want to go that
route.)

However, I speculate that you combine / split the ROIs so you
can move them all rigidly together. You can do this by selecting
in the ROI Manager the ROIs you wish to move together as a
group, and then run More >> Translate... from the ROI
Manager. (Selecting no ROIs counts for this purpose as selecting
all of the ROIs.) This will move all of the selected ROIs together
without changing their labels.

Would using More >> Translate.. accomplish what you are
trying to do?

(Note that the ROI Manager has a setting for whether it should label
ROIs with integers or with there names. Run More >> Labels...,
and you can toggle the “Use names as labels” check box.)

As for Fiji “changing the position” of your ROIs after splitting them,
I’m not sure I fully understand. If you move the combined ROI,
then when you split it, the individual ROIs – newly created by the
split – should indeed be moved. But I’m not sure that this is what
you are referring to.

If the split ROIs don’t line up with where they were in the combined
ROI (immediately before splitting), that would be a problem. (And
I don’t think that happens.) If you are having a problem with the
ROIs getting unexpectedly moved, please give us some more
detail about where in your workflow it happens.

Thanks, mm

1 Like

Hi @Ruth_EHR and @mountain_man,

My guess is that the effect you observe is not a change in positions but instead a reordering of the rois. This is due to the following: when you split a roi, the new rois will be added in order from top to bottom and left to right using their top-left bounding box coordinates. So, unless the starting array of rois is completely regular, as soon as you combine and split, the order will be messed up.

If the arrangement of the colonies is indeed regular, I would tackle this problem programmatically, generating the array of rois using a Script with some initial input from the user (perhaps a multipoint roi of the array “corners” ) or by detecting most of the colonies and “fitting” a new roi array (though this could be tricky to accomplish). In any case, this would compensate for translation and rotation errors of the images.

Cheers!
Nico

1 Like

Hi again, @Ruth_EHR !

I had a spare moment to try and actually implement my suggestion:

Here’s the code:

//delete preexisting ROIs
if (roiManager("count")>0) {
	roiManager("deselect");
	roiManager("delete");
}

nCols = 6; // number of columns
nRows = 8; // number of rows
diam = 25; // ROI diameter
rad = diam/2;

rowNames = newArray("A", "B", "C", "D", "E", "F", "G", "H");

setTool("polygon");
run("Select None");
makePolygon(146,98,485,94,489,569,150,568);
waitForUser("Adjust the polygon to the\n centers of the corner colonies");

if(selectionType()!=2) exit("Polygon Selection Needed");
getSelectionCoordinates(xp, yp);
if(xp.length!=4) exit("Four sided polygon needed");

x0 = xp[0];
y0 = yp[0];

//row and column (average) deltas: it allows for translation-rotation-shear of the array (i.e. affine)
dxCol = ((xp[1]-xp[0])+(xp[2]-xp[3]))/2/(nCols-1);
dyCol = ((yp[1]-yp[0])+(yp[2]-yp[3]))/2/(nCols-1);

dxRow = ((xp[3]-xp[0])+(xp[2]-xp[1]))/2/(nRows-1);
dyRow = ((yp[3]-yp[0])+(yp[2]-yp[1]))/2/(nRows-1);

for(i=0; i<nCols; i++){
	for(j=0; j<nRows; j++){
		makeOval(x0-rad+ i*dxCol + j*dxRow, y0-rad + i*dyCol + j*dyRow, diam, diam);
		Roi.setName(rowNames[j]+i);
		roiManager("add");

		}
}

roiManager("UseNames", "true");
roiManager("Show All with labels");

Let me know if it’s useful to you :smile:

Cheers!
Nico

1 Like

Hi mountain_man, sorry for the late reply, but thank you so much for getting back to me. We had tried the translate option in the ROI manager, I just wanted to find something that was easier/faster to use as I had to image so many plates. But before seeing @NicoDF 's answer we had decided to go ahead with this :sweat_smile:

Hi Nico, so sorry for the late reply. Thank you sooo much for this! This is amazing that you took time out of your day to write up the script for this. I have tried it on 4 plates and it works perfectly. I am honestly so thankful, this will help me so much as we hope to image 100s of plates in the coming months. This is also perfect as it means any rotation of the plate will not affect my measurements :raised_hands:

Once again, thank you so much for all your help :grin:

1 Like

Glad to know it fits your needs! :smile:

Good luck with your work,
Nico

1 Like