Created
June 20, 2020 06:35
-
-
Save petebankhead/db1cbe7c4767fc0392ab5fa0606d397a to your computer and use it in GitHub Desktop.
Script to export a rendered (RGB) image in QuPath v0.2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Script to export a rendered (RGB) image in QuPath v0.2.0. | |
* | |
* This is much easier if the image is currently open in the viewer, | |
* then see https://qupath.readthedocs.io/en/latest/docs/advanced/exporting_images.html | |
* | |
* The purpose of this script is to support batch processing (Run -> Run for project (without save)), | |
* while using the current viewer settings. | |
* | |
* Note: This was written for v0.2.0 only. The process may change in later versions. | |
* | |
* @author Pete Bankhead | |
*/ | |
import qupath.imagej.tools.IJTools | |
import qupath.lib.gui.images.servers.RenderedImageServer | |
import qupath.lib.gui.viewer.overlays.HierarchyOverlay | |
import qupath.lib.regions.RegionRequest | |
import static qupath.lib.gui.scripting.QPEx.* | |
// It is important to define the downsample! | |
// This is required to determine annotation line thicknesses | |
double downsample = 10 | |
// Add the output file path here | |
String path = buildFilePath(PROJECT_BASE_DIR, 'rendered', getProjectEntry().getImageName() + '.png') | |
// Request the current viewer for settings, and current image (which may be used in batch processing) | |
def viewer = getCurrentViewer() | |
def imageData = getCurrentImageData() | |
// Create a rendered server that includes a hierarchy overlay using the current display settings | |
def server = new RenderedImageServer.Builder(imageData) | |
.downsamples(downsample) | |
.layers(new HierarchyOverlay(viewer.getImageRegionStore(), viewer.getOverlayOptions(), imageData)) | |
.build() | |
// Write or display the rendered image | |
if (path != null) { | |
mkdirs(new File(path).getParent()) | |
writeImage(server, path) | |
} else | |
IJTools.convertToImagePlus(server, RegionRequest.createInstance(server)).getImage().show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment