Created
June 15, 2020 08:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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