Read an image that is not open

Hey I want to read the data from 2 pictures in a script. I can read it like this from the opened picture

def imageData = QPEx.getCurrentImageData()
def hierarchy = imageData.getHierarchy()
def server = imageData.getServer()
double downsample = 1.0            
def request = RegionRequest.createInstance(server.getPath(), downsample, 0, 0, server.getWidth(), server.getHeight())
def img = server.readBufferedImage(request)

Does anyone know how to read an image that is not open in this way?

Perhaps this post from @smcardle has the type of access you are looking for?
M9 Multiplex Classifier Script Updates (cell summary measurements/visualization)

1 Like

Here are some options that answer your question in different ways, depending upon what exactly you want

def path = '/path/to/the/image.ext'

// Read a small image with ImageIO
// ('normal' Java, nothing QuPath-specific)
def img = javax.imageio.ImageIO.read(new File(path))
println img

// Read a small image with ImageJ as an ImagePlus
// ('normal' ImageJ, nothing QuPath-specific)
def imp = ij.IJ.openImage(path)
println imp

// Read any image with QuPath as an ImageServer
def server = qupath.lib.images.servers.ImageServerProvider.buildServer(path, BufferedImage)
println server

// Read another image within a project as an ImageData (from which you can get the server)
def name = 'Image name as shown in Project pane'
def project = getProject()
def entry = project.getImageList().find { it.getImageName() == name }
def imageData = entry.readImageData()
println imageData

These assume you’re using the latest milestone version (currently v0.2.0-m9).

3 Likes