Hi @manaser, I agree with @Research_Associate and @oburri that it isn’t a problem with the segmentation but rather the expectation
@oburri’s approach is one way to deal with it, but I don’t think it will work directly because of the way Java handles drawing for 16-bit images – when I tried it, I ended up with hard-to-interpret labels.
In general, I am trying to get away from users needing to grapple with Java
BufferedImages and other such awkward things in favour of adding helper classes to QuPath to take care of all that.
This will allow scripts can be written at a higher level – and many of the complicated scripts floating around the internet (including this forum and my blog) will become unnecessary. You can see some examples of ‘newer’ scripts in Exporting annotations.
LabeledImageServer helpers used there don’t (yet) support the kind of labelled images that Oli is referring to (they will in the next version…), but another approach you can use is to export a two-channel binary image where the second channel stores the outline of each ROI.
Based upon the script in the tutorial, it might looks like this:
def imageData = getCurrentImageData()
// REMOVE THIS IS YOUR CELLS ARE ALREADY CLASSIFIED!!!!
// Need to classify the cells for this to work in v0.2.0-m11
// Define output path (relative to project)
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def pathOutput = buildFilePath(PROJECT_BASE_DIR, 'tiles', name)
// Define downsample
double downsample = 2
// Create an ImageServer where the pixels are derived from annotations
def labelServer = new LabeledImageServer.Builder(imageData)
.downsample(downsample) // Choose server resolution; this should match the resolution at which tiles are exported
.addLabel('Cell', 1) // SET THE LABEL OF THE CLASSIFICATION FOR YOUR CELLS
.setBoundaryLabel('Boundary', 2) // Set the boundary to be some unique label
.multichannelOutput(true) // If true, each label is a different channel (required for multiclass probability)
// Create an exporter that requests corresponding tiles from the original & labelled image servers
.downsample(downsample) // Define export resolution
.imageExtension('.tif') // Define file extension for original pixels (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(512) // Define size of each tile, in pixels
.labeledServer(labelServer) // Define the labelled image server to use (i.e. the one we just built)
.labeledImageExtension('.tif') // Extension for the associated labelled image
.annotatedTilesOnly(true) // If true, only export tiles if there is a (labelled) annotation present
.overlap(0) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput) // Write tiles to the specified directory
Note that you should read the script before running it - it’s quite likely you’ll need to adapt it for your purposes.