Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/aabe47d36c3ad753b2b362b67feff321 to your computer and use it in GitHub Desktop.
Save petebankhead/aabe47d36c3ad753b2b362b67feff321 to your computer and use it in GitHub Desktop.
QuPath v0.2.0 script to export color deconvolved tiles from a whole slide image to ImageJ TIFFs for further processing
/**
* Script to export color deconvolved tiles from a whole slide image in QuPath
* to ImageJ TIFFs for further processing.
*
* @author Pete Bankhead
*/
import qupath.lib.common.GeneralTools
import qupath.lib.images.ImageData
import qupath.lib.images.servers.ImageServerMetadata
import qupath.lib.images.servers.TransformedServerBuilder
import qupath.lib.images.writers.TileExporter
import java.awt.image.BufferedImage
import static qupath.lib.gui.scripting.QPEx.*
// Create an export path relative to the current project (requires that there *is* a project)
def path = buildFilePath(PROJECT_BASE_DIR, 'tiles')
mkdirs(path)
// Create an ImageServer that applies color deconvolution to the current image, using the current stains
def imageData = getCurrentImageData()
def server = new TransformedServerBuilder(imageData.getServer())
.deconvolveStains(imageData.getColorDeconvolutionStains())
.build()
// Slightly tortured way to control the output file names without all the stains encoded within it
server.setMetadata(
new ImageServerMetadata.Builder(server.getMetadata())
.name(GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName()))
.build()
)
// Export tiles
def exporter = new TileExporter(new ImageData<BufferedImage>(server))
.tileSize(1024, 1024) // Determines export tile size
.downsample(8.0) // Determines export resolution
.imageExtension('.tif') // ImageJ TIFF
.includePartialTiles(true) // Controls tiles as the boundary
// Uncomment this line if you want to see customization options
// println(describe(exporter))
// Write the tiles
exporter.writeTiles(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment