Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebankhead/6d3a220074a1cb99caf6dc92ab71bfed to your computer and use it in GitHub Desktop.
Save petebankhead/6d3a220074a1cb99caf6dc92ab71bfed to your computer and use it in GitHub Desktop.
Apply an Affine transform to the current image in QuPath v0.2.0 and write this as a pyramidal OME-TIFF file
/**
* Apply an Affine transform to the current image in QuPath,
* and write this as a pyramidal TIFF file.
*
* Note: Be careful with the pixel size! In v0.2.0 this is not automatically
* updated (later versions might correct this issue).
*
* @author Pete Bankhead
*/
import org.locationtech.jts.geom.util.AffineTransformation
import qupath.lib.gui.dialogs.Dialogs
import qupath.lib.images.servers.TransformedServerBuilder
import qupath.lib.roi.GeometryTools
import static qupath.lib.gui.scripting.QPEx.*
// Define transform
def transform = GeometryTools.convertTransform(
new AffineTransformation([2, 0, 0,
0, 4, 0] as double[]))
// May or may not need to create an inverse transform (depending upon what was defined)
// - remove this line if it isn't needed
transform = transform.createInverse()
def server = getCurrentServer()
def serverTransformed = new TransformedServerBuilder(server)
.transform(transform)
.build()
def file = Dialogs.promptToSaveFile("Save transformed image", null, null, "OME-TIFF", "ome.tiff")
if (file)
writeImage(serverTransformed, file.getAbsolutePath())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment