Removing out-of-focus objects



I’m sorry if this question has been answered previously.

I am constructing a pipeline to quantify nuclear morphology and I would like to exclude out-of-focus nuclei from the analysis.
Is there a module, analogous to the MeasureImageQuality module, that I can use to quantify the focus of each nuclei in an image?



There’s no official ‘MeasureObjectQuality’ module, but there are definitely ways to determine if any of our hundreds of object measurements can determine in-vs-out of focus for your nuclei:

Easy to set up, but slow and likely less accurate:
Simply go into your existing pipeline , downstream of your IdentifyModule add a bunch of Measurement modules, then either use the WorkspaceViewer (recommended) or DisplayDataOnImage (not as recommended) to look at some candidate measurements- off the top of my head, some of the Intensity Edge measurements, Granularity, Texture, or some of the Shape measurements could all be candidates.

More complicated to set up, but easier and more likely to succeed in the long run:
Create a QC pipeline that includes everything up to and including your nuclear identification, lots and lots of Measurement modules, then ExportToDatabase. You can then use CellProfiler-Analyst’s Classifier tool to actually sort in-focus from out-of-focus nuclei. CPA will then actually tell you which measurements are important for sorting in-focus from out-of-focus nuclei, and you can even save the rules it uses to sort those as a text file. In your original pipeline then, you can add the FilterObjects module (plus whatever measurements turned out to be important) and read that rules text file to apply that filtering to your whole data set. You can take a look at our tutorials page for a video tutorial of doing this in a previous version of Analyst.


Thanks for your reply and suggestions! I’ll have a play around and no doubt come back with more questions.


So I’ve got CPA 2.2.1 up and running and have started experimenting with the classifier tool. However I have a potentially stupid question: Where is the find rules button on the windows version of cpa 2.2.1?


Not a stupid question at all! Once you hit ‘train’ you should see a list of rules immediately above your unclassified images, and you can go to Advanced->Edit Rules- one thing I should’ve added in my previous post though, make sure to use the ‘Fast Gentle Boosting’ classifier (and probably more than 5 rules- maybe start with 20?) if you want to be able to use the rules in Filter Objects in CP later, since the other machine learning classifiers like Random Forest, etc calculate things a bit differently.


Thanks, that seems to work for me so far! I’ll start a new topic with my new problem…


I have been using CPA successfully to filter focused nuclei. However in my latest analysis I get the following error when I try to load the rules file into my CP pipeline:
invalid literal for float(): followed by two numbers from the first line of my rules file

I’m pretty sure I’ve not done anything drastically different than before, could you please advise me as to what this means and how I might rectify the problem.


Can you upload the rules file and the pipeline? Thanks.


Here you go. Thanks!
Script4_Nuclear_Measures_Focus_selected.cp (7.5 KB)
Rule for focus ID.txt (4.0 KB)


Hmmmm, I notice the file you uploaded has a .cp rather than .cppipe extension; are you still running a build of CP 2.0 by any chance? I’m not sure if this workflow works on builds of CP that old. In fact, given that there seem to be 3 classes in your rules file and support for >2 classes was only added after the last 2.0 release, I’m almost certain it won’t.

My strong suggestion would be to upgrade to a more modern version of CP. If for whatever reason that’s not possible, you will probably have to redo your classification to do only 2 classes at a time.


Ha! Yes that would explain it.
I was using an older version so I could overlay object outlines which I thought I could not do with a newer version (please correct me if I’m wrong).
Thanks for your help!


You can definitely overlay object outlines in newer versions of CP! I think the module name is the same in both- OverlayOutlines. If I’m not understanding your use case correctly, please let me know.


Oh cool, my mistake. Thanks for your help!