Performing calculations with objects from multiple images

Hi all,

I have the following setup: I take images of lung tissue in which I stained for two markers. I take like 50 images per tissue slice and I use CellProfiler to identify nuclei and positive cells, which works like a charm. Now I get a CSV file where the number of positive cells is given for each image. I add up the positive cells and nuclei for all images from the slice and then calculate the percentage of positive cells to nuclei. So far so good.

My question would be: Can I somehow do the adding-up process in CellProfiler? The slide number is parsed as Metadata and then all events from images with the same slide number are added up?

Is this possible?

Thanks a lot for the help!


Hi Till,

There is no built-in, simple way to do this that I know of (anyone else have ideas?). Certainly not faster than clicking below a column of values in Excel and clicking the AutoSum button, or a pretty easily constructed, pre-defined formula.

For the record, there are a few calculations in CP that can be done post-hoc on multiple cycles, possibly by group as you cite. There are DataTools from the menu at top which can be run on an output .mat file (but none that I know of that would do what you’re asking). There is the CalculateStatistics module, but again, it has specialized, pre-defined outputs. Your best best, if you need to do this more than a few times, is to write an Excel macro to act on the Per_Image csv file, or a Matlab script to act on the .mat file.


Hi again,

I wrote a little python script to perform the actions I have described above. I made it available on GitHub:

This script has been written for my purposes, but should be easy to understand and use. README is on the way.


Hi Till,

Thanks for making this available! We appreciate you sharing this, and we will check it out to see if it might be integrated into CP DataTool.


I just started to learn Python (I know PHP), so the programming might not be very advanced. Any comments are welcome.