Export TMA cores with Positive Cell Detection Overlay

Hi everyone,

I found a groovy script that allows me to export all the cores of a TMA as individual images that works very well. What I would like to do though is also export the same image with the overlay of the Positive Cell Detection results. I don’t need to use the images for data analysis at all, I just need the images for viewing purposes and in publications.
Below I am posting the script that Pete wrote that exports the individual images but I can not figure out how to adapt it to export the images with the Positive Cell Detection overlay.

Any help would be greatly appreciated,
Thanks!

import javax.imageio.ImageIO
import qupath.lib.regions.RegionRequest

// Define resolution - 1.0 means full size
double downsample = 1.0

// Create output directory inside the project
def dirOutput = buildFilePath(PROJECT_BASE_DIR, ‘cores’)
mkdirs(dirOutput)

// Write the cores
def server = getCurrentImageData().getServer()
def path = server.getPath()
for (core in getTMACoreList()){
// Stop if Run -> Kill running script is pressed
if (Thread.currentThread().isInterrupted())
break
// Write the image
img = server.readBufferedImage(RegionRequest.createInstance(path, downsample, core.getROI()))
ImageIO.write(img, ‘PNG’, new File(dirOutput, core.getName() + ‘.png’))
}
print(‘Done!’)

Have you looked into any of:





Or really, do a search for rendered images or overlays, there are quite a few posts on the topic, and which script you want to use will depend on exactly what your goals/original images look like.

Hi, thanks for getting back to me,

Yes, I found those suggestions and have tried them. I can’t get them to work in the context of exporting all of the TMA cores the way the script I included above does. I have found several other posts that deal with exporting TMA cores that deal with overlays and I have tried to get all of those to work but none do for me. I’m sorry, I don’t have any real coding experience so I am obviously doing something wrong but I can’t figure out what it is.

The code in my previous post exports all the images after the TMA has been de-arrayed. Now that I have those images, I just need the same images with the results of the Positive Cell Detection on top.

Thanks again

That ended up being more difficult for me than I thought, but the solution was a variant of the function on the Readthedocs page.

// Write the full image, displaying objects according to how they are currently shown in the viewer
double downsample = 10.0
def server = getCurrentServer()
def name = getProjectEntry().getImageName()
def viewer = getCurrentViewer()

getCurrentHierarchy().getTMAGrid().getTMACoreList().each{
    mkdirs(buildFilePath(PROJECT_BASE_DIR,'export'))
    def path = buildFilePath(PROJECT_BASE_DIR,'export', name+" "+ it.getName()+".tif")
    def request = RegionRequest.createInstance(server.getPath(), downsample, it.getROI())
    writeRenderedImageRegion(viewer,request, path)
}
print "Done"

Key change is that you need to use “writeRenderedImageRegion” instead of writeRenderedImage.

Note that it only uses your current display settings, this does not get into fully automating running the script from outside of QuPath or anything like that. You need an open image for it to get the display settings from.

1 Like

Brilliant!!

That works perfectly. Thanks for the extra note of warning at the end. For my purposes, I will only be exporting these images from the current display settings within QuPath so it does exactly what I need it to.

Thank you so much for your help, I really appreciate it!

1 Like