Skip to content

Instantly share code, notes, and snippets.

@romainGuiet
Last active December 20, 2019 11:31
Show Gist options
  • Save romainGuiet/96b017ab2c9a763e0a31017411bfe264 to your computer and use it in GitHub Desktop.
Save romainGuiet/96b017ab2c9a763e0a31017411bfe264 to your computer and use it in GitHub Desktop.
QuPath script (qps) to export the image annotations as a ROIset.zip in a '/ROI Sets' folder. The ROIset.zip saving/naming convention respect the ImageJ's BIOPLib.ijm (from PTBIOP update site).
// = CODE DESCRIPTION =
// Image annotations are saved as a ROIset.zip in a '/ROI Sets' folder, so they can be re-open in Image-j
// The ROIset.zip saving/naming convention respect the ImageJ's BIOPLib.ijm (from PTBIOP update site).
//
// == INPUTS ==
// A QuPath project, with annotations.
//
// == OUTPUTS ==
// The annotations are saved as a ROIset.zip in a '/ROI Sets' folder,
//
// = DEPENDENCIES =
// QuPath 0.1.4 ,
// biop-tools-1.1.6-SNAPSHOT.jar
//
// = INSTALLATION =
// Open the Script in QuPath, Run (work with Run for Project)
//
// = AUTHOR INFORMATION =
// Code written by Romain Guiet, EPFL - SV -PTECH - BIOP
// 20191219
//
// = COPYRIGHT =
// © All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, BioImaging And Optics Platform (BIOP), 2018
//
// Licensed under the BSD-3-Clause License:
// Redistribution and use in source and binary forms, with or without modification, are permitted provided
// that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
// TO DO : improvement would be to : don't get the ImagePlus nor open it to get the ROIs
import ij.*
import ch.epfl.biop.qupath.utils.*
import ij.plugin.frame.RoiManager
import qupath.lib.images.servers.*
def downsampleFactor = 1
// reset Env, close images & reset roiManager
IJ.run("Close All", "");
def rm = RoiManager.getInstance()
if(rm == null) rm = new RoiManager()
else rm.reset()
// get infos regrading the image
def images_dir = getCurrentImageData().getServer().getFile().getParent()
def image_name = getCurrentImageData().getServer().getShortServerName()
// make the output folder and file
def rois_dir = buildFilePath(images_dir , 'ROI Sets')
mkdirs( rois_dir )
def roiset_name = image_name+'.zip'
def roiset_path = new File (rois_dir, roiset_name)
// get the image
def fullImage_annotation = PathUtils.getFullImageAnnotation()
imp = GUIUtils.getImagePlus( fullImage_annotation , downsampleFactor , true, true )
imp.show()
// send overlay to roiManager & save the roiset
IJ.run("To ROI Manager", "");
rm.runCommand("Save", roiset_path.toString() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment