Can blobs be persistently named?

I have various discrete blobs ( call them “cells” ) in my images that I’d like to track even though I rotate or ( someday skew or otherwise use some affine transformation on) the image. If it’s just a rotation I can write code to transform the old centroid to a new centroid and locate where, say, cell #23 moved to.

But I was wondering if there’s some built-in clever way to tag each cell with a persistent number or name that survives image rotation. Ideas?

I guess I could make a mask-type RGB second image and color-code each cell to a unique color ( RGB has lots ) and transform both the second image along with the first one and look up the RGB color of the second image blob and translate back to a unique cell identifier in the first image positionally.

Just wondered if anyone else had ever had such a need or solved this question or if I missed some clever macro command.

Thank you!

thank you

Hi @CaptainRob,

I just tested this, in reponse to your query. If the cells/blobs are defined by an ROI that is added to the overlay, then ImageJ will update the ROI automatically upon image transformation… at least for the simple rotation that I performed in my testing. See this minimal example:

//create a new blank 8-bit image and put a 'cell' on it
newImage("Untitled", "8-bit black", 100, 100, 1);
setForegroundColor(255, 255, 255);
makeOval(9, 25, 21, 5);
run("Fill", "slice");
run("Select None");

//create a selection that defines the shape of the cell
setAutoThreshold("Default dark");
run("Create Selection");
//add our 'cell' ROI to the overlay
run("Add Selection...");
run("Select None");

//perform a simple transformation... 30 degreee rotation
run("Rotate... ", "angle=30 grid=0 interpolation=Bilinear");

It also seems to work for freehand selections. ImageJ is just amazing!

If you are used to working with the ROI manager, then you may have to adjust to working with an overlay instead. An added advantage to working with ROIs stored on the overlay, is that it is usually much faster (at least it used to be in my experience).

To use the overlay like the ROI manager, you may need to use macro commands like:

Overlay.activateSelection(index);

Anyway, perhaps your transformations are more complicated and the above may not apply. Just wanted to bring this to your attention in case it is useful.

Kind regards.

Also, one more thing to add that may more completely address your exact question, you can give the ROI a name with this macro command:

Roi.setName("Cell 1 or whatever");

which you can call just before adding the selection to the overlay, either as I posted before or with:

Overlay.addSelection("yellow", 0, ""); //first variable is outline colour, middle is line thickness, last is fill colour

Then, at the end of the macro, you can call the following if you want to display labels in situ:

Overlay.useNamesAsLabels(true);
Overlay.drawLabels(true);

Wasn’t sure if I really needed to add these extra details, but you did specifically mention names(labels) in your original query. All the relevant overlay macro commands are listed on the built-in macro commands page, as you would expect:
https://imagej.nih.gov/ij/developer/macro/functions.html#O