Scripts Not Working On My Image. Why?

Hi all,

I’m using a simple script that selects annotations for me using the automated script features. I’ve successfully ran this script on one of my images (.tif) and it worked no problem. However, I normalized the image using Matlab and saved it as a .tif again, and when I ran the same script on QuPath it wouldn’t work. I get no errors, the script simply won’t execute and create the box. Does anyone know why this is happening? The normalized image and the non-normalized images are both .tif and are the same dimensions as well.

It really isn’t possible to say without knowing what script you ran or confirming that both images open fine within QuPath, and also which version do QuPath you are using.

Here is the script for creating the annotations (below). I’m using QuPath (0.1.2)

import qupath.lib.objects.PathAnnotationObject
import qupath.lib.objects.classes.PathClassFactory
import qupath.lib.roi.RectangleROI
import qupath.lib.scripting.QPEx

// Define the size of the region to create
double sizeMicrons = 545.0

// Get main data structures
def imageData = QPEx.getCurrentImageData()
def server = imageData.getServer()

// Convert size in microns to pixels - QuPath ROIs are defined in pixel units of the full-resolution image
int sizePixels = Math.round(sizeMicrons / server.getAveragedPixelSizeMicrons())

// Get the current viewer & the location of the pixel currently in the center
def viewer = QPEx.getCurrentViewer()
double cx = viewer.getCenterPixelX()
double cy = viewer.getCenterPixelY()

// Create a new Rectangle ROI
def roi = new RectangleROI(cx-sizePixels/2, cy-sizePixels/2, sizePixels, sizePixels)

// Create & new annotation & add it to the object hierarchy
def annotation = new PathAnnotationObject(roi, PathClassFactory.getPathClass(“Region”))
imageData.getHierarchy().addPathObject(annotation, false)

The two images are both .tif and are the same dimension (2000x2000), and the Norm image is the normalised image.

The script works perfectly for the first image, but not the second :frowning:

Because the script uses sizes in microns, my guess is that this pixel calibration info hasn’t been written to the tiff file in MATLAB.

You can confirm this by checking under the ‘Image’ tab.

One solution would be to define everything in pixels within the script instead.

2 Likes

THANK YOU!!! Yep, that was it! I love you <3