Can one export the area of tumor/stroma cells in QuPath?

Hi all,

I wish to export the total area covered with tumor/stroma?



Going to need more specifics. Are you trying to export the area as a mask or a single value in um^2? Also, there are several methods of determining area that can be found on the old forums, in addition to the pixel classifier with the new release, but some of these are better in certain situations than others. Positive pixel detection works great if you are doing a cytokeratin H-DAB, but wouldn’t work well at all for an H&E.

1 Like

I have a TMA and I wish to determine what is the um^2 area of stroma/tumor classified cells, while using H&E as the method of cell detection.

Then that second link should do it.

Thanks. This is script I’ve adapted for this purpose… perhaps if would be useful to other folks as well

// Add percentages by cell class to each TMA core

import qupath.lib.objects.PathCellObject
def hierarchy = getCurrentHierarchy()
def cores = hierarchy.getTMAGrid().getTMACoreList()

//Complete list of all classes 
def list = ["Tumor", "Stroma"]

cores.each {
    //Count cells and measure area in the core
   def total = hierarchy.getDescendantObjects(it, null, PathCellObject).size()
   //Prevent divide by zero errors in empty TMA cores
   if (total != 0){
      for (className in list) {
        def cellType = hierarchy.getDescendantObjects(it,null, PathCellObject).findAll{it.getPathClass().toString().contains(getPathClass(className).toString())}
        def cellTypeSize=cellType.size()
        double totalArea = 0
        for (def cell in cellType){
            totalArea += cell.getMeasurementList().getMeasurementValue("Cell: Area")
        println(it.getName() +" cell_count "+ cellTypeSize + " " + className + " %cell " + cellTypeSize/(total)*100+ " total_area "+ totalArea + " mean_cell_area " + totalArea/cellTypeSize )
   else {
     for (className in list) {
        println(it.getName() +" "+className+" cell %" + 0)
1 Like

Something I found in one of Pete’s scripts helped generalize that sort of script for random classes people might come up with.

def list = new ArrayList<>(getDetectionObjects().collect {it.getPathClass()} as Set)

Note: If you have subcellular objects, you probably will want to be specific and use getCellObjects() or similar depending on your target detection type. This was just the most generic option.

Thanks for the suggestion. Do you happen to know what are the units by which the area is represented in this script?

ROI areas by default are in pixels. Since the script reports only percentages, no conversion was necessary, but if you want to report actual areas you will need to multiply out by the pixel height and width.
*oops, after quickly checking, this script does not use ROI areas, but the Cell: Area measurement, which is in microns squared. The getArea() function is what I was thinking of that reports pixels and is most often used in scripts.
And further edit, haha, it looks like your script reports areas, not percentages! Very much thinking of a different script.

Also Pete’s script from the link above is… destructive (and you should copy your project before running it), but might give a more accurate measurement depending on cell density since it will include the larger amounts of space between cells in the stroma.