I used the script below to export tiles from annotated regions. The annotated regions and tiles have no tumor (see image). There are two issues:
-
First, the number of tiles displayed in QuPath is not equal to the number of tiles exported. The number of annotated tiles that I can see in QuPath is less than half of the number of patches that were exported.
-
Second, I noticed that occasional exported patches have tumor clusters. As mentioned, when I look in QuPath at the annotated area, there is no tumor. The tumor clusters that are seen in the patches are close to the annotated regions but not in the annotated regions.
I am using QuPath version 0.2.3 and am using a Windows 10 operating system. I do not see anything directly relevant to this in the forum or in QuPath documents (https://qupath.readthedocs.io/en/latest/docs/advanced/exporting_images.html).
import qupath.lib.images.servers.LabeledImageServer
def imageData = getCurrentImageData()
// Define output path (relative to project)
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def pathOutput = buildFilePath(PROJECT_BASE_DIR, 'tiles', name)
mkdirs(pathOutput)
// Define output resolution
//double requestedPixelSize = 0.2465
// Convert to downsample
double downsample = 1 //requestedPixelSize / imageData.getServer().getPixelCalibration().getAveragedPixelSize()
// Create an ImageServer where the pixels are derived from annotations
def labelServer = new LabeledImageServer.Builder(imageData)
.backgroundLabel(0, ColorTools.WHITE) // Specify background label (usually 0 or 255)
.downsample(downsample) // Choose server resolution; this should match the resolution at which tiles are exported
.addLabel('Other', 1) // Choose output labels (the order matters!)
.multichannelOutput(true) // If true, each label is a different channel (required for multiclass probability)
.build()
// Create an exporter that requests corresponding tiles from the original & labeled image servers
new TileExporter(imageData)
.downsample(downsample) // Define export resolution
.imageExtension('.png') // Define file extension for original pixels (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(512, 512) // Define size of each tile, in pixels
// .labeledServer(labelServer) // Define the labeled image server to use (i.e. the one we just built)
.annotatedTilesOnly(true) // If true, only export tiles if there is a (labeled) annotation present
.overlap(0) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput) // Write tiles to the specified directory
print 'Done!'