How to assign specific colors to Objects based on MeanIntensity measurements?



First of all, thanks for the CellProfiler development team. CellProfiler is a amazing image tool that saves me heaps of time when need to deal with many images.

I am currently trying to differentiate two cell types based on their intensity differences from two channels (i.e. Alexa594 and DAPI) after using certain probes. By using CP, I was able to extract intensity information from each channels for each identified objects in a given image. We could clearly see two populations when plotting MeanIntensity_Alexa594 against MeanIntensity_DAPI (Please see attached scatter plot). May I ask if there is a way to assign different colors to the objects that being classified to either two populations?

I have tried Pair of Measurements within ClassifyObjects, however, 1) the options list there (i.e. Mean, Median and Custom) could not reveal the relationship we observed from the scatterplot. 2) I also got error message “Error while processing ClassifyObjects: boolean index did not match indexed array along dimension 0; dimension is 2271 but corresponding boolean dimension is 2270”.

I attached a sample data and the pipeline. I am running CP 313 on MacOS 10.13.1, java version “1.8.0_152”.

I really appreciate if you may help me for this question.

Best regards,
Jun (3.7 MB)



Glad you are enjoying the software! Hopefully someone with more up to date knowledge can chime in, but I wonder if the FilterObjects module might be a decent workaround?

I believe there is a bug that is interfering with ClassifyObjects at the moment:



Hi Anne,

Thanks for your prompt reply.

After working around FilterObjects module with Measurements mode, I was able to obtain filtered object. And by using CovertObjectsToImage and SaveImages modules, I could obtain binary images of filtered objects and all identified objects, respectively. Then, solid colors could be assigned to these two binary images and overlaid together in imageJ. This workflow almost solved the posted question.

However, there is still a small issue. The gate created in FilterObjects is an rectangle, which could not include all objects in a given population (from the attached scatter plot, we can see that the shape of the population is a ellipse).

I also tried Classifier in CPA (My idea is that maybe machine learning is clever enough to find out to use MeanIntensity_Alexa594 and MeanIntensity_DAPI to classify all objects. And then I can use the classifiers in the FilterObjects module), however, after following the tutorial and clicking “Train”, I got the following error message:

An error occurred in the program:
IOError: [Errno 32] Broken pipe

Traceback (most recent call last):
  File "/Applications/CellProfiler", line 1370, in OnTrainClassifier
  File "/Applications/CellProfiler", line 1408, in TrainClassifier
    self.algorithm.Train(self.trainingSet.label_array, self.trainingSet.values, output)
  File "/Applications/CellProfiler", line 160, in Train
    print self.classifier

The training process was then stopped with 0% complete.




Indeed, FilterObjects only allows hard thresholds in each feature dimension so I agree it’s not a perfect workaround. I suspect you could do the ImageJ bit in CP too if it’s important to make a single pipeline to accomplish everything.

Ah, ok, I see your scatterplot now-sorry I didn’t see it before (was answering on my phone). Hm. At one point in history you could plot a density plot (or perhaps scatterplot?) of the data in CellProfiler Analyst and then circle a population using whatever shape you like, manually, and then… hm, I don’t recall whether it let you assign a tag to those cells within the outlined population in a way that lets them be labeled in the field of view image.

I think it would be a pain to get Classifier to recognize the population of interest - seems overly complex given that you can see the populations so nicely in a scatterplot. I’m not sure why that error appears.

Sorry I cannot help more than that!



Thanks again for your help :grinning:. I will keep trying and post here if any solution comes up.

BTW, why is this function cancelled?




Oh, ha, well it may still actually work! I just haven’t checked it in ages.



I think I may have thought of something clever… If you use the CalculateMath module to divide (for each object) one metric by the other (possibly with some adjustment factor), can you in essence “tilt” the scatterplot so that the two clouds are nicely horizontal? If so then you can use FilterObjects on that new, single metric with a single threshold!



Hi Anne,

That is possible when there are only two distinct populations, however, in my case, sometimes more than two populations could be identified (Please see the attached scatter plot), which make it hard to find a single threshold for all populations using CalculateMath.

As in R, I can make polygon gates on the scatterplot and assign objects in different populations with different labels (for example, a new column named ObjectLabel with values). May I ask if there is a way to import this file as a Rules file back into CP in FilterObjects module? Something like this: IF (ObjectLabel == [value]).

I really appreciate your help.




FYI, the solution for the quoted issue is that: save the training set and restart the CPA and reload the training set, all done.

1 Like


Ah, too bad! I think using CPA to score the cells of interest might work, even though it’s an overly complicated solution to your simple problem.

I don’t think it will work to transform your gates into the rules of Filter Objects (because it involves a single threshold for each channel) or even Classify objects which takes in a CPA set of rules (because it would be super hard to translate your gates into its style rules).

I suspect a Jupyter notebook or R script would be the most straightforward approach, unfortunately. The options in CPA involve straight cutoffs for features, or machine learning, but not the gating approach which falls somewhere between!