How can averaged object measurements be sent to annotation measurements?

113 views
Skip to first unread message

Al

unread,
Apr 3, 2019, 6:32:53 AM4/3/19
to QuPath users
Hi Qupathers!
I'm trying to compare the total mean fluorescent intensity of cells in different annotations. I have annotations with multiple cells and want to make an average "Cell: Channel 1 Mean" measurement for all cells and then send the result to annotation measurements so I have a single figure for each annotation. I've tried a few of the scripts in here https://gist.github.com/Svidro/68dd668af64ad91b2f76022015dd8a45 but none of them do quite what I want to do.
Thanks,
Alan

micros...@gmail.com

unread,
Apr 3, 2019, 10:45:12 AM4/3/19
to QuPath users
Note that forum is now here: https://forum.image.sc/tags/qupath

It sounds like you basically want this one within the list you posted. You just need to change the sum created from all cells from "area" to your measurement of interest, and then divide by the number of cells rather than the total area. If you don't want a particular class, remove the findAll that selects only a given class.

Al

unread,
Apr 3, 2019, 12:09:20 PM4/3/19
to QuPath users
Hi micros, thank you so much, I have it working! Here is an adapted version of the script for fluorescent channel intensity. Will switch to the new forum. Thanks again!  

import qupath.lib.objects.PathCellObject

hierarchy = getCurrentHierarchy()

for (annotation in getAnnotationObjects()){
    def allCells = hierarchy.getDescendantObjects(annotation,null, PathCellObject)
    double totalintensity = 0
    for (def cell in allCells){
        totalintensity += cell.getMeasurementList().getMeasurementValue("Cell: Channel 1 mean")
    }
    //Comment the following in or out depending on whether you want to see the output
    println("Mean intensity for allCells is: " + totalintensity/allCells.size)
    println("Total intensity is: " + totalintensity)
    
    //Add to annotation measurements
    annotation.getMeasurementList().putMeasurement("Ch1 Mean Intensity", totalintensity/allCells.size)
    annotation.getMeasurementList().putMeasurement("Ch1 Total Intensity", totalintensity)
   }
Reply all
Reply to author
Forward
0 new messages