How can I obtain a table relating nucleus number and area of each cell?

Dear ImageJ community,

Could you kindly help me with this? I’m trying to count automatically on the same image: cell number, area of each cell and nuclei per cell. My goal is to represent as coordinates nuclei number (x) vs area (y) of each single cell. (Nuclei and area com from separate channels)

I have no problem on counting per separate cell and nuclei number. How can I obtain a table relating nucleus number and area of each cell?

Thanks for your time

Hi @Quique

If you can isolate the objects of interest in each channel, you can build up each “object” of interest as a ROI (region of interest) in ImageJ. You can then analyze the ROIs to determine which overlap, and record this information in the results table.

I created a template macro that I think covers everything you want to do.

In fact, this template actually does more than you want as it was written for 3-channel data with several interactions of interest. I would suggest using it as a starting point - removing the parts you don’t need.

If you have limited programming experience, the wiki has a macro guide that covers the basic techniques that are used in this macro (variables, loops, conditional statements).

Just let us know if you get stuck. Sharing your macro code and a sample image at that point will help.


Hi @hinerm ,

Unfortunately my programming knowledge is restricted to basic R stuff. Despite I tried to modify that template macro, i got lost… At this point, what I reached was to get two separate roi sets (one for the nuclei and the other for the cell areas) as two zip files. My goal is just to count the ROI number (“nuclei” roi set) contained inside each ROI of the other ROI set (“areas”).

The other option would be to count the particles contained in each ROI of the “area ROI set”. However, I only know how to do this one by one (would it be possible to automatically count this particles of all ROIs at the same time?)

No worries. It definitely was too complicated. I made an effort to generalize it to a 2-channel version that focuses on just finding overlap. Here is the new version

The script is divided into “big channel” (your area rois) and “small channel” (your nuclei rois) preprocessing and analysis steps. If you can modify those sections to generate the ROIs sets you have pictured, then the rest of the macro will determine the overlap and nuclei counts.

If it’s still too complicated for you to modify… can you share an unmodified original image (e.g. via upload sample image), and the steps you’re using for preprocessing and analysis? (e.g. if you use the macro recorder to record what you did to produce those rois, and paste the recorder output here, that should be enough)


Hi @hinerm ,First of all, thanks for your time and your answer. I did not expect you would reply with such detail!

This is what the macro recorder showed:

// In order to obtain the area rois, I did this:
run("Split Channels");
setAutoThreshold("Default dark");
//setThreshold(3, 255);
run("Convert to Mask");
// Then I saved the RoiSet and counted nuclei:
run("Nucleus Counter", "smallest=10 largest=50000 threshold=Current smooth=None subtract watershed");
// And then I saved this second RoiSet

I tried to start step by step the process from the begginning with your macro, but I got a problem (I assumed I should use “IJ1 Macro” as a language). I first opened the image (.tif format) and run lines 38 and 39, so the image is splitted. However, seems that lines 45 and 46 don’t work (bigChannel = 1; smallChannel = 2;), because lines 57 and 59 give this error back:

selectImage("C"+<bigChannel> + "-" + title);

Is it maybe a problem of the image format? Should it be .tif? RGB or composite? Is there any alternative way to rename the channel? (NB: my “areas” are on channel green and nuclei on channel blue)

Thanks again for your time

You are correct! Sorry you have to paste it into the editor for now. Eventually you will be able to select the script from the Templates menu of the script editor, which will automatically choose the correct language. But I want to make sure it’s useful first. (thank you, also, for testing my script :smile:)

I am assuming you were using the Run selected code feature? Unfortunately, running only parts of a macro doesn’t always work. In this case the problem is that I declare a few variables so that you can tune the output to your particular dataset. These variables only “exist” when the macro runs. So, if you partially execute the macro and create these variables, and then try to run later parts via Run selected code, it will have forgotten the existence of these variables :frowning: which is why you got the odd error message.

Would you feel comfortable trying again, now that you know that the whole macro should be executed? It looks like the processing you’re doing is very straightforward so I am confident that this macro can fit your needs, with minor changes. It’s also valuable for me to see what problems you encounter (for example, I will now add a warning about “run selected code” use!).

Anyway if you can’t get it to work just let me know!

P.S. if you want to temporarily disable part of the macro, you can comment it out with multi-line comments, like this:

here is an active line of code

none of the code
between these comment markers
will be executed

You could also have a look at the BioVoxxel Speckle Inspector. It looks as if this is exactely the kind of analysis you are looking for.

1 Like

Thanks @MartinH that’s exactly what I was looking for!!

At the end I nearly managed to make it work (but despite obtaining everything thresholded it ended selecting the last ROI and didn’t show the result). Fortunately, the BioVoxxel Specke Inspector that @MartinH recommended worked perfectly. Anyway, thanks for your help, I learned a lot of new things about ImageJ :smile:

How did you please count the cells automatically ?