Simple way of matching nexted ROIs (Cell, Nucleus) for Localization studies

Sample image and/or code


I am trying to look an nuclear localization of a transcription factor in response to IGF1. These are fixed and labeled with GFP. I also have a dapi stain. Also the cells are embedded in agarose so they are 3D spherical objects. I do have a membrane stain but I forgot to apply it. I will redo this experiment but I wanted to see how far I can get with what I have.

Analysis goals

I would like to get the ratio of GFP intensity of nucleus to the cytosol. Activation would be a higher ratio and low the opposite.

What I have tried

So I am new to ICY and I have been working with the HK Means plugin to get my ROIs. I have a good handle on that. What I have so far is a manual process where I extract the channels, do a z projection and do the ROI identification on each separately, so I have a list of nucleus and cells in some random order. When I cut and paste they are sort of matched up but not quite. I have been trying to manually click through and notate which ones are the pairs. This is not a sustainable path forward.

Ideally I am looking for something akin to cell profiler where you could look inside an existing ROI to find the nucleus so there is some linkage. I have never looked in separate channels in cell profiler so I am not sure it has this ability. I would be willing to try and make my own plug in for it. the pseudo code would be

  1. take image
  2. Pre process if necessary ( smooth sharpen etc…)
  1. look in Channel 1 to identify cells
  2. Lookin Channel 2 to identify nuclei in each of said cells
  3. calculate the intensity of Channel 3 in just the nuclei
  4. calculate the intesnity of the cells indentified in step 3 minus the nuclei in step 4

I would need some way of pairing the two ROIs so I would not have to manualy pick and do binary operations to get what I want.

Thanks in advance for the help!

Dear Matt,

I am afraid there is no “simple” way to do what you would like to do in Icy, but there is a way :slight_smile:
I would do an Icy “protocol”. Icy protocols are graphical programming tools to design advanced bioimage analysis workflows and/or automate a task. You don’t need to know how to program in order to create a protocol.

The protocols editor is located in the Tools tab. You can load an existing .protocol file with the Load button and create a new protocol with the New button. To get started with protocols, I recommend reading the Icy protocols documentation.

I created the following protocol:protocol_associate_ROIs.protocol (23.7 KB)
It won’t work directly: you need to modify file paths, add a block to project the 3D stack in 2D (Intensity Projection block), HK-Means parameters are not the same as yours etc.

It is made of 5 parts:
a) and b) are HK-Means segmentations on channel 1 and channel 2 (actually channel 0 and channel 1, because channels start at 0 in Icy)
c) adds information in the name of the nuclei ROIs to identify the cytoplasm they belong to
d) creates cytoplasm ROIs without the nucleus
e) gets all fluorescence intensity measures and saves them in an Excel spreadsheet

For steps c) and d), it loops over each nucleus and each cytoplasm to find correspondance between ROIs that are intersecting. I didn’t put “contained” in case the nucleus is sometimes on the edge of the cytoplasm and not all pixels of the nucleus ROI are contained in the cytoplasmic ROI. Step d) does the exclusive union when there is a match, in order to create the cytoplasmic ROI without the nucleus.

I hope this helps.

Best regards,


Thank you so much. Is there a plugin developer IRC channel or google group? I would be willing to try and code up a plugin that would keep track of related sub components. I am not super skilled but I have some coding experience.

1 Like

You’re welcome!
All communication between Icy users is centralised here on the forum.
To discuss about Icy plugin development, choose the “Development” category and add the tag “icy”.

To get started with Icy plugin development, you can watch the video of the tutorial “Developing your own Icy plugins” that was given by @Stephane and @dgonzale for the I2K 2020 online conference and have a look at the associated slides.

Note that, depending on your coding experience and the language(s) you are familiar with (and time you can dedicate to create you bioimage analysis workflow), an alternative to writing a plugin would be to add JavaScript or PythonScript blocks to a protocol.

Have fun with Icy!
Best regards,

1 Like

Hi Matt,

Marion already made a pretty complete reply :slight_smile:
Still i think you can find attached nuclei ROI by using block like Logical operation ROI, which allow to filter ROIs on intersection or contain test, you also have the ROI Inclusion analysis block, it won’t be useful in the current case but always good to know that exits :slight_smile:


– Stephane

1 Like

Useful discussion not only for me but I think others see this useful discussion for them as well, thank you all! :handshake:

1 Like



I adapted your protocol and I think it works but I am not sure how to export all the data out to a workbook. I am confused since you have many of the last blocks in a loop block. I am not sure how to get data on All the ROIs out of the protocol. I am interested in getting intensity and shape data from all the ROIs identified. How would I do that?

Thanks in advance


Dear Matt,

The blocks in step e) compute all measurements including intensity and shape on all the ROIs identified and export the results to a spreadsheet.

They do the following operations:

  • Get ROI from sequence: get all the ROIs on the image (all the ROIs computed in c) and d))
  • Set ROI position C: set the ROIs on all channels
  • ROI Statistics: compute the ROI Statistics (you need to give the name of the input sequence to get the fluorescence intensities)
  • Workbook to file: export the results to a spreadsheet (either .xlsx if you keep “spreadsheet” or .txt if you use “Text” as file format). In output file, you need to select a path to a folder and complete it with a file name, for instance “/results.xlsx”. If you only provide a folder name, it won’t work.

It is important that the group of blocks in e) executes after all the other blocks. To check the order of block execution, have a look at the number in the upper right corner of the blocks. If these blocks execute before, the Get ROI from sequence block will not collect all the ROIs on the image.
It is also important to keep the Add ROI to sequence (or Add rois) blocks in c) and d). Get ROI from sequence block gets only the blocks that were added to the sequence.

Best regards,

1 Like

@MarionLouveaux OK. I think I am about there. One thing that I am worried about is the stringency of that check to see if the nucleus is intersected by the cell. So I have been running the protocol on a single image and I checked the HK means setting manually. My problem is nothing makes the cut. Looking at the ROIs generated from the manual HK means there is no way this should not happen.

I am not sure how to trouble shoot. I wind up with an empty file since nothing seems to be pass the intersection test. Do you have any suggestions how I trouble shoot. Is there a way to have pause buttons or variable display to debug what s going on?

Thanks in advance

1 Like

@Stephane @MarionLouveaux I am redoing the protocol from scratch and trying to not use deprecated blocks. How can one loop through images using ranges loops instead of array loops. I am not sure how to take my list of ROIs and loop through them 1. I am hoping to troubleshoot why the logical operator on the ROI is failing. I ran the plugin ROI Inclusion analysis and it successfully matches the ROIs. The problem is the output is a workbook and I do not see away of continuing from a block with just an workbook/analysis output.

My attempt is shown below. I am using the indexer and the range loops. I pass the loop paraemeters from the lists. The code does not execute properly. This should be a nested loop but it behaves like to loops back to back. How do I control execution so the inner loop completes prior to running the next iteration of the outer loop.

Any suggestions would be much appreciated.

1 Like

Dear Matt,

Regarding your first message:
From what I understand, steps a) and b) output some ROIs, but no intersection between ROIs is found in step c). To check how are the ROIs from a) and b), I would connect a block Add rois to the list of ROIs from each HK-Means block and visually inspect the image to see if the ROIs intersect.

More generally, to debug a protocol:

  • I check and re-check the order of execution of blocks (number in the upper right corner of the block).
  • I run the protocol piece by piece: if you click on the small run icon in the upper left corner of the block, it runs the protocol until this block only. For a batch/loop block, it will do only one iteration.
  • I use Display blocks to display values (images, TRUE/FALSE, number, text…) and check that this matches my expectations.

protocol_display_ROI_number protocol_display_boolean protocol_display_decimals protocol_display_image

Regarding your second message:
Indeed the Array block is deprecated, I didn’t pay attention to this :roll_eyes:. It is now replaced by the Batch block, which also works with a ROI array.


At this point, I would suggest you to upload the protocol you are creating and a test image, this will be way easier to help you.

Best regards,

1 Like

endogenous DMSO.tif (9.0 MB)

2nd attempt.protocol (23.3 KB)

@MarionLouveaux I am grateful if you can help me track this down where the bug is…

I have attached my protocol. I think I have faithfully reproduced your example with the exception of swapping the array loop with batch. The program runs much faster ~5 seconds now. Before it would take like 20 minutes. I have around 100 cells that I am trying to match the Inclusion plug in does this fairly quickly and is accurate. I think the issue is I fail the intersection test.

Also I tried just click on the play arrow for the loop block but it executes the entire loop and not just a single iteration. Is there some setting I need switch to get that behavior that would make diagnosing much easier.

@Stephane @MarionLouveaux

test_case.tif (39.1 KB) protocol_associate_ROIs_modified.protocol (23.5 KB)

Ok I am stumped I cannot get the a list of ROI that match up. I have uploaded a simplistic cartoon example to try and diagnose. I do see blocks changing but I never have more than one ROI in the add ROI. I am also not clear on how to get a data out of the loop. I am limited on what blocks can expose the ROI list and sequence. I noticed there is no direct connection so I am assuming the link is just using the active sequence. Is there a way to avoid that?

Also beyond the loops Add ROI to sequence is deprecated. I am not sure what I should use that will be supported going forward.

any help would be much appreciated.

Dear Matt,

I tested the 2nd attempt.protocol and the protocol_associate_ROIs_modified.protocol with the example images you provided. I also tested again protocol_associate_ROIs.protocol with these data.
I will try to summarise what I see and identify potential sources of issues.

About the images you sent:

  • I noticed that the “endogenous DMSO.tif” is an RGB image
  • I also noticed that there is a scale bar imprinted on it
  • And I have the impression that the metadata (pixel size of 1 micron in x and y) are not correct (notably because the scale bar given by Icy does not match the imprinted scale bar)

I guess this image is not what was originally created by your microscope. I recommend using the original format instead, in order to keep as much information as possible. Icy uses the Bioformat library, which is able to open most of the microscopy image formats (see all formats supported by bioformat).

About the protocol_associate_ROIs_modified.protocol (the first one I wrote):

  • I adjusted the parameters in HK-Means blocks to match yours (I used the ones in the 2nd attempt.protocol)
  • I selected the “endogenous DMSO.tif” sequence in the two Extract channels blocks and in the Get roi from sequence block and changed the channel numbers to match the ones in your image
  • I chose a path to save the results in the output file parameter of the Workbook to file block
  • I ran the protocol.
  • I opened the ROI tab and clicked on Name to rearrange ROIs by name. This protocols creates green ROIs for cytoplasm -I decided to call the cytoplasm by the name of the nucleus that was substracted- and blue ROIs for nuclei -with the name of the nuclei glued to the name of the cytoplasm-.

About the 2nd attempt.protocol, I found several issues:

  • I noticed that you use “A_CONTAINED_IN_B” as condition to keep ROIs. This is too restrictive. A ROI is “contained” in another ROI when absolutely all the pixels underneath ROI A are also underneath ROI B. It only takes one pixel on the outside for the ROI A not to be contained in ROI B. I recommend to use “A_INTERSECTING_B” instead. It will keep ROI A as long as there is at least one pixel in common.
  • I noticed that you inverted A and B compared to my protocol. I used A = nuclei ROIs and B = cytoplasmic ROIs, and you did the opposite. I guess this could create some issues, although I did not had time to investigate further.
  • I also noticed that you added the ROIs (Compile ROIs is number 7) to the image before setting their names (Set ROI name is number 9). If you do so, the new name will not be taken into account.
  • Most importantly, I noticed you use the block File to sequence. It means that you are working on an unopened image (contrary to my protocol, where I open an image in Icy, and select it in the Extract channel block either on its name or as “Active sequence”). In this case, you need to use the block Save metadata, for instance connect it like this at the end of the protocol

About the protocol_associate_ROIs_modified.protocol, the only issue I found is the condition to keep ROIs. You used “A_NOT_INTERSECTING_B”, which will keep all nuclei not intersecting with cytoplasm B
intersection .

Changing this condition to “A_INTERSECTING_B” gives the right result:

This protocol will work on the “endogenous DMSO.tif” image if you adjust the HK-Means parameters.

The Add ROI to sequence block is indeed deprecated and replaced by the Add rois block.

Best regards,

1 Like


Pipeline works! I have one parting question… If I wanted to adapt this to 3D I could just covert a z stack and feed it through? The trains make it seem pretty seemless switching to volumes. I can’t visualize in 3d at all do to the vtk bug but hopefully I can process with a protocol blindly.

Is that possible?

1 Like

Great!! :+1:

Yes, it should work directlty in 3D: HK-Means can work in 3D, as well as all the operations on ROIs.

1 Like