@@ -0,0 +1,1781 @@
+package io;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport net.imglib2.realtransform.AffineGet;%0Aimport net.imglib2.realtransform.AffineTransform;%0A%0Apublic class AffineImglib2IO%0A%7B%0A%0A%09public static AffineTransform readXfm( int ndims, File f ) throws IOException%0A%09%7B%0A%09%09return readXfm( ndims,%0A%09%09%09%09new String( Files.readAllBytes( Paths.get( f.getAbsolutePath() ))));%0A%09%7D%0A%09%0A%09public static void writeXfm( File f, AffineGet affine ) throws IOException%0A%09%7B%0A%09%09String s = %22%22;%0A//%09%09System.out.println(affine.toString());%0A%09%09%0A%09%09for( int r = 0; r %3C affine.numDimensions(); r++ )%0A%09%09%7B%0A%09%09%09for( int c = 0; c %3C affine.numDimensions() + 1; c++ )%0A%09%09%09%7B%0A%09%09%09%09s += affine.get( r, c );%0A%09%09%09%09if( r %3C affine.numDimensions() - 1 %0A%09%09%09%09%09%09%7C%7C c %3C affine.numDimensions() )%0A%09%09%09%09%7B%0A%09%09%09%09%09s += %22, %22;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A//%09%09System.out.println( s );%0A%09%09List%3CString%3E lines = new ArrayList%3CString%3E();%0A%09%09lines.add( s );%0A%09%09Files.write( Paths.get( f.getAbsolutePath() ), lines );%0A%09%7D%0A%09%0A%09public static AffineTransform readXfm( int ndims, String s )%0A%09%7B%0A//%09%09System.out.println( s );%0A%09%09AffineTransform xfm = new AffineTransform( ndims );%0A%09%09String%5B%5D array = s.replaceAll( %22 %22, %22%22 ).split( %22,%22 );%0A%09%09int row = 0;%0A%09%09int col = 0;%0A%09%09for( String elem : array )%0A%09%09%7B%0A//%09%09%09System.out.println( %22row: %22 + row );%0A//%09%09%09System.out.println( %22col: %22 + col );%0A//%09%09%09System.out.println( %22elm: %22 + elem );%0A%09%09%09xfm.set( Double.parseDouble( elem ), row, col );%0A%09%09%09col++;%0A%09%09%09if( col == ( ndims + 1 ) )%0A%09%09%09%7B%0A%09%09%09%09col = 0;%0A%09%09%09%09row++;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09return xfm;%0A%09%7D%0A%09%0A%09public static void main( String%5B%5D args ) throws IOException%0A%09%7B%0A%09%09AffineTransform xfm = readXfm( 3, new File( args%5B0%5D) );%0A%09%09System.out.println( xfm );%0A%09%09writeXfm( new File(%22%22), xfm );%0A%09%7D%0A%0A%7D%0A

add affine reader for imglib2