Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save petebankhead/c9f6aed95b38996b2380b09134f2251b to your computer and use it in GitHub Desktop.
Save petebankhead/c9f6aed95b38996b2380b09134f2251b to your computer and use it in GitHub Desktop.
Import images from .qpdata files into a new project in QuPath v0.2.x.
/**
* Import images from .qpdata files into a new project in QuPath v0.2.x.
*
* The purpose of this is to help recover data from files that were saved outside a project.
* It may not work for all images, but should work for most 'straightforward' examples (i.e. a single image per image file).
*
* If your .qpdata files are already part of a v0.1.2 project, use 'File -> Project... -> Import images from v0.1.2' instead.
* If your .qpdata files are already part of a v0.2.0 project, use 'File -> Project... -> Add images' and add the .qpproj file instead.
*
* Warning! This hasn't been very extensively tested (I always use projects from the start...).
* Always be cautious, back up your .qpdata files first - just in case something goes wrong.
*
* (See https://forum.image.sc/t/qpdata-file-in-a-project/41520/ for the discussion leading to this script.)
*
* @author Pete Bankhead
*/
import static qupath.lib.gui.commands.ProjectImportImagesCommand.*
def project = getProject()
if (project == null) {
Dialogs.showNoProjectError("Import .qpdata error")
return
}
def dir = Dialogs.promptForDirectory(null)
def files = dir.listFiles( {it.getName().endsWith('.qpdata')} as FileFilter)
for (file in files) {
try {
def imageData = qupath.lib.io.PathIO.readImageData(file, null, null, BufferedImage)
def entry = addSingleImageToProject(project, imageData.getServer(), null)
entry.saveImageData(imageData)
} catch (Exception e) {
println 'Unable to add ' + file
println e
}
}
getQuPath().refreshProject()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment