Counting the nuclei in the labelled cells


I recently met Cell Profiler which seems great! I need to prepare a pipeline for myself but I couldn’t figure out a few things. I seed two different types of cells in my plates and need to count only one type which is detected by a cytoplasmic marker (Alexa 555,). Among the cells I need to count, I also need to separate them as positive or negative against a second marker (Alexa 488). In short, I need to count how many nuclei (seen in DAPI) are present under the red mask (555) and how many of them are green (488). My first problem is identifying the red area, and cropping the rest of the image where there are other DAPI labelled nuclei which I’m not interested in. I attached one image. In this one there are two DAPI labelled nuclei which I want to exclude, one is outside of the red mask while the other is on top of the red area. How can I do these two types of exclusions?

The order of my pipeline is
ColorToGray (my images are in RGB) --IDPrimAuto – IDSecAuto – IDTert – OverlayOutline

Can I do this with the crop module? If so, how can I specify the red areas?

Secondly in the case of thresholding, I tried but Otsu and MoG but they basicly divide a single nuclei into lots of different regions even though I chose “shape” for distinguishing clumped objects. Then, I tried interactive settings and set up an absolute threshold. Do I need to set the threshold each time or am I not using Otsu/MoG right?

Final question is if I have images with different magnifications, do I need to change the diameter range of nuclei in the module?

Many thanks in advance!


1 Like

Hi Gozde,

Your pipeline is pretty close to what it needs to be. I’ve attached a revised pipeline, which works as follows:

  • I chose RobustBackground as the thresholding method and increased the correction factor. The nuclei in the green channel are very bright, so that works to your advantage if you need to change these settings. RobustBackground works well if most of your image is background (i.e., dark); if this is not the case for a given image, you may need to change to a different method.

  • The next step is to use IDSecondary to get the red cells, and then crop the blue image into the red cell shape. You can then threshold the blue image with a per-object method to get the DAPI nuclei.

  • Cropping into the red cells is sufficient to get rid of the nuclei outside of the cells. However, dealing with the one within the red area is harder. So I expanded the green nuclei using IDsecondary to make sure they fill out the same area as the blue nuclei, and then masked the blue image with them. The result is an image with the blue nuclei unaccounted for using the green image, and these nuclei can be identified using IDPrimAuto again. The results are then saved to an outline image and a spreadsheet.

The last step is a little kludgey, but hopefully it’s sufficient to work well for you. The outlines may not be exact, but at least the nuclei count should be correct.

2009_12_03_PIPE.mat (1.91 KB)

Thanks very much Mark!

All the best,


Hello Mark,

I wanted to ask one more question but I keep receiving the following: “the board attachment quota has been reached” even though I decreased the size of the image. What is the limit?

What can I do?

Thanks very much


Hi Gozde,

We’re increased the limit, so you should be able to upload your images/pipeline now.



I still can’t upload anything…

Well, perviously I asked for help about counting green labelled-nuclei with a red cytoplasmic marker and differentiating them from other nuclei (detected with DAPI only) even though they might overlap with green nuclei. In this case, I had double control with green nuclear and red cytoplasmic marker.

However, now I need to differentiate the cells just based on the red cytoplasmic marker. Need to count the DAPI labelled nuclei under red mask let’s say (the cells with red cytoplasmic marker) and in addition I need to count the number of green nuclei again under the same red mask. Sometimes there are nuclei touching the ones with red cytoplasmic marker which makes things even more difficult.

Here is an example image and the pipeline I used to use before: … E.mat.html

Sorry, I couldn’t upload them here. Could you please help me with the pipeline?

In addition, I was wondering besides red-blue-green channels if I use far red channel and colour it with magenta in my images will I be able to use it with Cell Profiler or does it only work with RGB channels? One more question about image resolution: How much difference does resolution of images make in CellProfiler? What would your suggestion be?

Thanks very very much for your help.



I’m still trying to optimise my pipeline. Could you please please help me optimise it?

I have two type of cells in my image and I need to count the ones with red cytoplasmic marker. In addition to this I need to count how many of those have green labelled-nuclei. I have tried many things but I’m still failing to identify red cells correctly. And when I crop it, it seems CP works on the region I want to get rid of rather than on the area of interest.

I would be very grateful if you help me with this. I don’t want to count hundreds of images manually :frowning:

Thank you!

Testpipe28Jan09.mat (1.6 KB)


The images you have uploaded here are at a lower resolution than the original one you posted on 12/3/09. IdentifyPrimAuto has several size dependent parameters which need to be set correctly for the pipeline to work properly. The original pipeline was optimized for the original image, so with these new images, these parameters need to be set accordingly.

Originally, the size criteria in IdentifyPrimAuto were set for objects between 50 - 150 pixels in diameter. With these new images, something like10 - 50 pixels is more appriopriate. Since some of other parameters in the module depend on these size settings being set correctly, the module failed as a result. If you need to, you can inspect distances in an image using CellProfiler Image Tools > ShowOrHidePixelData in any CellProfiler window of the image of interest.

Also, I think a SmoothOrEnhance module before the 1st IdentifyPrimAuto module would be helpful to reduce the amount of background flourescence being detected. Set the input as OrigBlue, the method as “Enhance speckles” and the filter size as a value larger than the largest nuclei diameter you expect (30 pixels in this case seemed to work well) Then make sure that the output image is given as input to the 1st IdentifyPrimAuto module.

In general, it is best to make sure that your image acquisition requires no further modification (e.g., no further changes to resolution, camera exposure, etc) before setting up your pipeline, so that you will be making a proper comparision in pipeline performance.



Thanks very much for your help. However, I guess I’m still missing a few adjustments. My pipeline follows the follwing order:
Colour to gray (my images are in RGB)
Smooth or Enhance (as you suggested)
IDPrimAuto( to choose all blue nuclei)
IDSec(To choose the nuclei with red cytoplasmic marker -red cells-)
Crop (to crop the resulting image into the shape of red cells)
IDPrimAuto(to choose blue nuclei of red cells only)
IDPrimAuro(to choose green nuclei of red cells again)
Overlay outlines

But it seems my image is not cropped into red cells instead the initial image is used for every cycle. My second problem is I can’t identify blue and green nuclei correctly. Instead, the same group of blue nuclei (even some of the ones without red cytoplasmic marker are chosen) are chosen in every cycle. What am I forgetting between these cycles? What do I need to change/add?

I have one more question. In terms of resolution of images what would you suggest to use? And I was also wondering if I use an additional marker in my images detected with far red and coloured as magenta lets say, will I be able to use this channel as well? It seems even in colour to gray, CP splits into 3 channels only.

Thanks very much.

Kind regards,


Ah, in your pipeline, in IDSec, OrigBlue is selected as the image to use to find the cell edges, instead of OrigRed. Change this setting and it should work.

Dear Mark,

Thanks very much for your very quick answer and sorry for being a pain but I still can’t crop the image properly and can’t identify green and blue nuclei either.

Testpipe29Jan09.mat (1.79 KB)


I’m sorry, I think I mis-read what you were attempting to do; thanks for your patience. I’m attaching a pipeline which idenitfies the features you’re looking for. The one main addition is the use of the Exclude module, to get rid of objects outside the red cell mask. Also, I changed the thresholding method for the red cells to Otsu global and adjusted the correction factor, as well as the segmentation settings for the blue/green cells.

Re: Multi-channel processing - The ColorToGray module can handle up to 3 channels per image, i.e., RGB. Any more than that, will require multiple image files. The easiest solution is to output your image data as individual grayscale images, one for each channel, and use LoadImages to proceed each set of N channels.

re: Resolution - The answer to depends on how well your pipeline is identifying the features that you want. If you find that that very small dim objects are unable to be detected regardless of how you tweak the settings, you may need to increase the resolution. For a simple cell count, you can probably still achieve good performance with smaller images. However, if you are interested in morphological measurements, then the image resolution will be more of an issue.

In any case, as mentioned earlier, remember to change the size-dependent settings if you choose to change the resolution. For example, the same settings could not be used on the Test1 and Test2 images, since the resolution is different; since Test3 is about half the resolution of Test1, the size settings in IDPrimAuto and SmoothOrEnhance had to be reduced by half as well, which is what the pipeline is set to.

Hope this helps!
2010_01_29_PIPE.mat (1.8 KB)

Dear Mark,

Thanks very much for your help now I inderstand the modules better. I played a bit more and the pipeline seems to be working :smile: May I have another question though? Is that possible to modify the final excel sheet which shows the results? In my case, I need the counts of both masked blue and green nuclei but excel shows only all blue nuclei and masked green nuclei numbers.

Thanks very much again.

All the best,


Unfortunately, the Exclude module doesn’t output these directly (which is a bug), but you can get the masked blue object count by adding the following modules:

  • ConvertToImage: Apply this to the masked blue objects with the binary setting to obtain an binary image of the objects.

  • IdentifyPrimAuto: Identify the masked blue objects from the binary image. Set the discard objects outside the diameter range and touching the border to ‘No’, the threshold method to “Other…” and enter 0.5, “Do not use” for distinguishing clumped objects, and “No” for “Do you want to fill objects…”

The masked blue object count will then be output as a measurement.



I am having trouble trying to count cells, these cells are stained with DAPI (blue). But, my pipeline is not working, it is counting a lot of cells (out of range). Also, I am trying to measure green fluorescence but I believe I need a new pipeline too. Could you please help me?

Thank you,

Hello there,

Can you demonstrate to us your pipeline (directly uploaded here), so we can assist the specific steps that needs tuning?


count cells.cpproj (428.5 KB)
Intensity.cpproj (435.3 KB)