Skip to content

Instantly share code, notes, and snippets.

@petebankhead
Last active March 31, 2021 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/863352f92d17facb15bb5cf35ed03f56 to your computer and use it in GitHub Desktop.
Save petebankhead/863352f92d17facb15bb5cf35ed03f56 to your computer and use it in GitHub Desktop.
Try to extract the label from an image in QuPath v0.2 and display it in ImageJ with enhanced contrast
/**
* Try to extract the label from an image and show this with enhanced contrast using ImageJ as the viewer.
*
* This is mostly intended for .czi files, where currently the label seems to be 16-bit
* and displays as entirely black in QuPath.
*
* It assumes that the label exists as an 'associated image' within the server.
*
* This has been tested with QuPath v0.2 - it may not work with other versions.
*
* @author Pete Bankhead
*/
import qupath.imagej.gui.IJExtension
import javax.swing.SwingUtilities
def server = getCurrentServer()
def labelImageName = server.getAssociatedImageList().find {it.toLowerCase().contains('label')}
if (labelImageName == null) {
println "Unable to find an associated image with 'label' in the name"
return
}
def img = server.getAssociatedImage(labelImageName)
// Show using ImageJ, with enhanced contrast
SwingUtilities.invokeLater {
IJExtension.getImageJInstance()
def imp = IJTools.convertToUncalibratedImagePlus(labelImageName, img)
ij.IJ.run(imp, "Enhance Contrast...", " ")
imp.show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment