Skip to content

Commit

Permalink
Add groovy script for applying a transform
Browse files Browse the repository at this point in the history
See #42
  • Loading branch information
bogovicj committed Oct 27, 2017
1 parent 6d72463 commit 35e25b7
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions scripts/Apply_Bigwarp_Xfm.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// @File(label="Landmark file") landmarksPath
// @File(label="Moving image file") movingPath
// @File(label="Target image file (optional)", required=false) targetPath
// @String(label="Interpolation", choices={"Linear", "Nearest Neighbor"}) interpType
// @int(label="Number of threads", min=1, max=64) nThreads

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import bdv.ij.ApplyBigwarpPlugin;
import bdv.img.TpsTransformWrapper;
import bdv.img.WarpedSource;
import bdv.viewer.Interpolation;
import bdv.viewer.SourceAndConverter;
import bigwarp.BigWarp.BigWarpData;
import bigwarp.BigWarp;
import bigwarp.BigWarpARGBExporter;
import bigwarp.BigWarpExporter;
import bigwarp.BigWarpInit;
import bigwarp.BigWarpRealExporter;
import bigwarp.landmarks.LandmarkTableModel;

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
import ij.plugin.PlugIn;
import jitk.spline.ThinPlateR2LogRSplineKernelTransform;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imglib2.realtransform.InverseRealTransform;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.integer.ByteType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;

println landmarksPath
println movingPath
println targetPath

movingIp = IJ.openImage( movingPath.getAbsolutePath() );
targetIp = movingIp;

if ( targetPath != null )
targetIp = IJ.openImage( targetPath.getAbsolutePath() );

int nd = 2;
if ( movingIp.getNSlices() > 1 )
nd = 3;

ltm = new LandmarkTableModel( nd );
try
{
ltm.load( landmarksPath );
} catch ( IOException e )
{
e.printStackTrace();
return;
}

Interpolation interp = Interpolation.NLINEAR;
if( interpType.equals( "Nearest Neighbor" ))
interp = Interpolation.NEARESTNEIGHBOR;

ImagePlus warpedIp = ApplyBigwarpPlugin.apply( movingIp, targetIp, ltm, interp, nThreads );
warpedIp.show();

0 comments on commit 35e25b7

Please sign in to comment.