Select and measure multiple ROIs within the bigger ROI

Hi guys,
I’m a complete novice in imaging/Fiji, and can’t find a solution for the next task:
I have an image of multiple nuclei, which I segmented using the StarDist plugin. StarDist highlighted all segmented nuclei as ROI. In the centre of the image, I have an anatomical region, within which I need to measure the cell nuclei quantity and area. So, on a single image, I have multiple ROIs of cell nuclei and one big ROI of the anatomical region.
How do I exclude the cell nuclei ROI outside the big ROI of the anatomical region?

I believe this post has a similar problem, but I do not understand the code and how to use it in practice:

Many thanks for your help,
Kseno

1 Like

Hi Kseno!

In theory, the ‘AND’ function in the Roi Manager (“More >>” menu) should so that for you (as described in the ‘Expert Roi Manipulation’ box in this excellent resource by @petebankhead. In practice, however, I could not get that to work in my hands and I’m not sure why…

A simpler workaround might be to duplicate your original image (Ctrl+Shift+D), apply the big ROI to this duplicate and clear outside (Edit > Clear Outside), and then run StarDist on this image. This is what it looks like in my hands (with the Versatile Fluorescent Nuclei model in StarDist run on the ImageJ test image ‘blobs’).

It’s not the most elegant solution and someone likely has a better way of doing this, but this might be sufficient in the meantime until that better solution appears :blush:

Cheers,
Siân

2 Likes

That will do, thanks a lot!
You made my day:)

Cheers,
Kseno

I think using AND on a group of ROIs like that would result in no ROIs, as it is ANDing all of the ROIs to each other, not all of the cell ROIs to the large ROI. So any two cell ROIs that don’t overlap would result in the deletion of all ROIs.

If you merged all of the cell ROIs into a single ROI, you could AND that with the large ROI and get a single ROI that was all of the cells. You would then have to split that back up into individual cells.

I think.

1 Like

Yes, this is totally it, nice!

So @Kseniia, the steps to do it that I have just tested to do what you originally asked are:

  1. Select all StarDist ROIs in the ROI manager, press More >> OR (combine) in the ROI manager. Then press Add (or t on the keyboard) and it will add a new ROI that is all the StarDist ROIs combined into one
  2. In the ROI manager, then select this new ROI and your ‘mask’ ROI, and press More >> AND. Then press Add (or t) and this will give an ROI that is the intersection of your mask and all the previous ROIs.
  3. If you then want to get the individual StarDist ROIs back out from this combined ROI, select it in the ROI manager and then press More >> Split.

This is almost certainly a better way of doing this than my original suggestion, as it avoids changing the properties of your original image :slight_smile:

Thanks @Research_Associate!

Cheers,
Siân

3 Likes

Thanks a lot! You both are my saviours, truly.

Cheers,
Kseno

1 Like

I’m afraid this won’t lead to the desired result, since StarDist ROIs are allowed to overlap.

Combining all ROIs with OR will indeed create a selection with all cells, that subsequently can be masked using AND, but once you reach:

… you’ll notice that previously overlapping separate ROIs will now be single merged ROIs.


There are other ways to solve this, e.g. using labeling images provided by #imglib2 that allow for overlapping labels, but solutions like that would require either some scripting, or switching to a more powerful framework such as #knime.

1 Like

Fair point. I think you can turn off the option for overlap in StarDist? Or maybe that is QuPath only.

Though QuPath is another way of running StarDist and isolating objects using an ROI like this.

And I suppose in ImageJ you could probably write a loop that ANDs each individual cell annotation with the large drawn annotation (and regenerates the drawn annotation after each AND). Not too experienced with ImageJ coding though.