/
Apply_Bigwarp_Xfm.groovy
49 lines (40 loc) · 1.48 KB
/
Apply_Bigwarp_Xfm.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#@ File (label="Landmark file") landmarksPath
#@ File (label="Moving image file") movingPath
#@ File (label="Target image file") targetPath
#@ String (label="Transform type", choices={"Thin Plate Spline", "Affine", "Similarity", "Rotation", "Translation" }) transformType
#@ String (label="Interpolation", choices={"Linear", "Nearest Neighbor"}) interpType
#@ Integer (label="Number of threads", min=1, max=64, value=1) nThreads
#@ Boolean (label="Virtual stack?") isVirtual
import java.io.File;
import java.io.IOException;
import bdv.ij.ApplyBigwarpPlugin;
import bdv.viewer.Interpolation;
import bigwarp.landmarks.LandmarkTableModel;
import net.imglib2.realtransform.BoundingBoxEstimation;
import ij.IJ;
import ij.ImagePlus;
movingIp = IJ.openImage( movingPath.getAbsolutePath() );
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;
bboxEst = new BoundingBoxEstimation();
emptyWriteOpts = new ApplyBigwarpPlugin.WriteDestinationOptions( "", "", null, null );
warpedIpList = ApplyBigwarpPlugin.apply(
movingIp, targetIp, ltm, transformType,
"Target", "", bboxEst, "Target",
null, null, null,
interp, isVirtual, nThreads, true, emptyWriteOpts );
warpedIpList.get(0).show();