Flip image or annotation

Working with QuPath 0.2.3

I have annotated tiff slides scanned using philips scanner.
We recently rescanned the same slides using Aperio, but the svs images appear mirror flip across the x axis.
The images from the tiff and svs are not identical (from x and y dimension) but contain same tumor and tissue. I managed to copy qpdata to the new images. The tumor annotation is there, but does not align well since the svs is mirror flipped . Is there a way to flip the annotations or the images?

Happy Holidays

Here is where I remember seeing a related discussion, see if that helps.

1 Like

Jumping on this thread because I have a similar question (I need to make mirrored pairs of annotations within the same image). I’ve been trying to use the code from that original post but it seems it no longer works with latest versions of QuPath and my coding skills are not yet up to updating it! Is anyone able to help?

And here is the better way, the original link has been updated to 0.2.0: Flip a ROI vertically or horizontally in QuPath v0.2 · GitHub

There is probably a better way to do this now, but this should at least work. Note the commented out line for vertical flips.

import qupath.lib.objects.PathAnnotationObject
import java.awt.geom.AffineTransform

// Get selected object & its ROI
def selected = QPEx.getSelectedObject()
def roi = selected?.getROI()
if (roi == null) {
    print 'No ROI selected!'

// Create the relevant transforms, incorporating the image dimensions
def server = getCurrentImageData().getServer()

def flipHorizontal = AffineTransform.getScaleInstance(-1, 1)
flipHorizontal.translate(-server.getWidth(), 0)

def flipVertical = AffineTransform.getScaleInstance(1, -1)
flipVertical.translate(0, -server.getHeight())

// Get a Shape for the ROI & apply required transform
def shape = roi.getShape()
def shape2 = flipHorizontal.createTransformedShape(shape)
//def shape2 = flipVertical.createTransformedShape(shape)

// Create & add a new annotation
def roi2 = RoiTools.getShapeROI(shape2, ImagePlane.getDefaultPlane(), 0)
addObject(PathObjects.createAnnotationObject(roi2, selected.getPathClass()))

Perfect! Thank you so much!!

1 Like

It looks like the script @Research_Associate posted is based on one I wrote some years ago for QuPath v0.1.2.

Here’s a link to the original source, I’ve updated it now for v0.2 and to handle multiple objects:


Yep, it was the one linked above.