Created
July 25, 2019 18:16
-
-
Save bogovicj/9f683a519341787111b29ca5244b90db to your computer and use it in GitHub Desktop.
An imagej2 example script for running bigwarp and getting at its landmark pairs
This file contains hidden or 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
#@ Dataset (label="moving image") mvgImg | |
#@ Dataset (label="target image") tgtImg | |
#@ File (label="landmarks file csv", required=false ) landmarksFile | |
import bdv.util.*; | |
import bdv.viewer.*; | |
import net.imagej.*; | |
import bigwarp.*; | |
import net.imglib2.*; | |
import net.imglib2.util.*; | |
import net.imglib2.type.numeric.*; | |
import net.imglib2.realtransform.*; | |
/** | |
* Build a bdv source from a imagej2 Dataset | |
*/ | |
def srcFromDataset( Dataset data ) | |
{ | |
axisScales = new double[ 3 ]; | |
for (i in (0..2)){ | |
axisScales[ i ] = mvgImg.axis( i ).calibratedValue( 1.0 ); | |
} | |
srcTransform = new AffineTransform3D(); | |
srcTransform.set( | |
axisScales[0], 0, 0, 0, | |
0, axisScales[1], 0, 0, | |
0, 0, axisScales[2], 0 ); | |
println( srcTransform ) | |
return new RandomAccessibleIntervalSource( | |
data, (NumericType)Util.getTypeFromInterval( data ), | |
srcTransform, data.getName()); | |
} | |
// make bigwarp sources from the dataset | |
mvgSrcList = [ srcFromDataset( mvgImg )] as Source[]; | |
tgtSrcList = [ srcFromDataset( tgtImg )] as Source[]; | |
// set up bigwarp | |
bw = new BigWarp( BigWarpInit.createBigWarpData( mvgSrcList, tgtSrcList, null ), "bigwarp", null ); | |
// load landmarks if there are any | |
if( landmarksFile != null ) | |
bw.getLandmarkPanel().getTableModel().load( landmarksFile ); | |
// loop through landmarks | |
landmarkTable = bw.getLandmarkPanel().getTableModel(); | |
for (i in (0..<landmarkTable.getRowCount())) | |
{ | |
println( i ) | |
mvgImagePoint = landmarkTable.getMovingPoint( i ) | |
tgtImagePoint = landmarkTable.getFixedPoint( i ) | |
println( mvgImagePoint ) | |
println( tgtImagePoint ) | |
println( ' ' ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment