本文整理汇总了Java中net.imglib2.realtransform.AffineTransform3D.rotate方法的典型用法代码示例。如果您正苦于以下问题:Java AffineTransform3D.rotate方法的具体用法?Java AffineTransform3D.rotate怎么用?Java AffineTransform3D.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.realtransform.AffineTransform3D
的用法示例。
在下文中一共展示了AffineTransform3D.rotate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotationCentered
import net.imglib2.realtransform.AffineTransform3D; //导入方法依赖的package包/类
/**
* Computes a rotation about an input center point
*
* @param axis
* @param angle in radians
* @param center
* @return
*/
public static AffineTransform3D rotationCentered( int axis, double angle, double[] center)
{
/******************************/
AffineTransform3D xfm = new AffineTransform3D();
xfm.rotate( axis, angle );
int ndims = center.length;
double[] target = new double[ ndims ];
xfm.apply( center, target );
double[] diff = ArrayUtil.subtract( center, target );
for (int i = 0; i < ndims; i++) {
xfm.set(diff[i], i, ndims);
}
/******************************/
return xfm;
}
示例2: main
import net.imglib2.realtransform.AffineTransform3D; //导入方法依赖的package包/类
public static void main(String[] args)
{
Img< FloatType > a = ImgLib2Util.openAs32Bit( new File( "73.tif.zip" ) );
Img< FloatType > b = ImgLib2Util.openAs32Bit( new File( "74.tif.zip" ) );
TranslationGet t1 = new Translation3D();
TranslationGet t2 = new Translation3D(460, 0, 0);
ArrayList< Pair< RealInterval, AffineGet > > views = new ArrayList<Pair<RealInterval, AffineGet>>();
views.add( new ValuePair< RealInterval, AffineGet >( a, t1 ) );
views.add( new ValuePair< RealInterval, AffineGet >( b, t2 ) );
RealInterval overlap = BoundingBoxMaximalGroupOverlap.getMinBoundingIntervalSingle( views );
final RealInterval transformed1 = TransformTools.applyTranslation( a, t1, new boolean[] {false, false, false} );
final RealInterval transformed2 = TransformTools.applyTranslation( b, t2, new boolean[] {false, false, false} );
// get overlap in images' coordinates
final RealInterval localOverlap1 = TransformTools.getLocalOverlap( transformed1, overlap );
final RealInterval localOverlap2 = TransformTools.getLocalOverlap( transformed2, overlap );
// round to integer interval
final Interval interval1 = TransformTools.getLocalRasterOverlap( localOverlap1 );
final Interval interval2 = TransformTools.getLocalRasterOverlap( localOverlap2 );
//final WarpFunction warp = new TranslationWarp(3);
final WarpFunction warp = new RigidWarp(3);
//final WarpFunction warp = new AffineWarp( 3 );
// rotate second image
AffineTransform3D rot = new AffineTransform3D();
rot.rotate( 2, 2 * Math.PI / 180 );
RandomAccessibleInterval< FloatType > rotated = Views.interval(
RealViews.affine(
Views.interpolate( Views.extendBorder( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ),
rot.copy() ),
interval2);
// show input
new ImageJ();
ImageJFunctions.show( Views.interval( a, interval1 ), "target" );
ImageJFunctions.show( rotated, "in");
// downsample input
RandomAccessibleInterval< FloatType > simple2x1 = Downsample.simple2x( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), new boolean[] {true, true, false} );
RandomAccessibleInterval< FloatType > simple2x2 = Downsample.simple2x( Views.zeroMin( Views.interval( rotated, interval2 ) ), new ArrayImgFactory<>(), new boolean[] {true, true, false} );
// align
//Align< FloatType > lk = new Align<>( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), warp );
Align< FloatType > lk = new Align<>( simple2x1, new ArrayImgFactory<>(), warp );
//System.out.println( Util.printCoordinates( lk.align( Views.zeroMin( Views.interval( b, interval2 ) ), 100, 0.01 ).getRowPackedCopy() ) );
//final AffineTransform transform = lk.align( Views.zeroMin( rotated ), 100, 0.01 );
final AffineTransform transform = lk.align( simple2x2, 100, 0.01 );
final AffineTransform scale = new AffineTransform( 3 );
scale.set( 2, 0, 0 );
scale.set( 1, 1, 1 );
transform.preConcatenate( scale );
// transformation matrix
System.out.println( Util.printCoordinates( transform.getRowPackedCopy() ) );
// correct input and show
RandomAccessibleInterval< FloatType > backRotated = Views.interval(
RealViews.affine(
Views.interpolate( Views.extendBorder( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ),
rot.copy().preConcatenate( transform ).copy() ),
interval2);
ImageJFunctions.show( backRotated, "out" );
// constructor needs column packed matrix, therefore the transpose
Matrix mt = new Matrix( transform.getRowPackedCopy(), 4).transpose();
Matrix rigid = mt.getMatrix( 0, 2, 0, 2 );
// check whether result is rotation matrix (det == +-1, orthogonal)
System.out.println( rigid.det() );
System.out.println( Util.printCoordinates( rigid.times( rigid.transpose() ).getRowPackedCopy() ) );
}
示例3: updateBDV
import net.imglib2.realtransform.AffineTransform3D; //导入方法依赖的package包/类
private void updateBDV()
{
BigDataViewer bdv = parent.bdvPopup().getBDV();
if ( bdv != null )
{
//FilteredAndGroupedExplorerPanel.resetBDVManualTransformations( bdv );
RegularTranslationParameters params = new RegularTranslationParameters();
params.nDimensions = 3;
params.alternating = alternating;
params.dimensionOrder = dimensionOrder;
params.increasing = increasing;
params.overlaps = overlaps;
params.nSteps = steps;
params.keepRotation = rotate;
Dimensions size = parent.getSpimData().getSequenceDescription().getViewDescriptions()
.get( selectedVDs.get( 0 ).get( 0 ) ).getViewSetup().getSize();
List< Translation3D > generateRegularGrid = RegularTranformHelpers.generateRegularGrid( params, size );
int i = 0;
for ( List< BasicViewDescription< ? > > lvd : selectedVDs )
{
// we did not generate enough transformations
// -> leave the rest of the views as-is
if (i>generateRegularGrid.size())
break;
for ( BasicViewDescription< ? > vd : lvd )
{
int sourceIdx = StitchingExplorerPanel.getBDVSourceIndex( vd.getViewSetup(), parent.getSpimData() );
SourceState< ? > s = parent.bdvPopup().getBDV().getViewer().getState().getSources().get( sourceIdx );
ViewRegistration vr = parent.getSpimData().getViewRegistrations().getViewRegistration( vd );
AffineTransform3D inv = vr.getModel().copy().inverse();
AffineTransform3D calib = new AffineTransform3D();
calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() );
//invAndCalib.preConcatenate( vr.getTransformList().get( 0 ).asAffine3D() );
AffineTransform3D grid = new AffineTransform3D();
if (i < generateRegularGrid.size())
grid.set( generateRegularGrid.get( i ).getRowPackedCopy() );
AffineTransform3D gridTransform = ( i < generateRegularGrid.size() )
? inv.preConcatenate( grid.copy() ) : inv.copy();
gridTransform.preConcatenate( calib );
if (rotate)
{
AffineTransform3D rotation = new AffineTransform3D();
Pair< Double, Integer > rotAngleAndAxis = RegularTranformHelpers.getRoatationFromMetadata( vd.getViewSetup().getAttribute( Angle.class ) );
if (rotAngleAndAxis != null)
{
rotation.rotate( rotAngleAndAxis.getB(), rotAngleAndAxis.getA() );
gridTransform.preConcatenate( rotation.copy() );
}
}
( (TransformedSource< ? >) s.getSpimSource() ).setFixedTransform( gridTransform );
}
i++;
}
bdv.getViewer().requestRepaint();
}
}
示例4: applyToData
import net.imglib2.realtransform.AffineTransform3D; //导入方法依赖的package包/类
public static void applyToData(Map<ViewId, Translation3D> locations, boolean pixelUnits, boolean keepRotation,
AbstractSpimData< ? > data)
{
if (data == null)
return;
final Map< ViewId, Translation3D > transformsForData = getTransformsForData( locations, pixelUnits, data );
final Collection< BasicViewDescription< ? > > vds = (Collection< BasicViewDescription< ? > >) data.getSequenceDescription().getViewDescriptions().values();
for ( BasicViewDescription< ? > vd : vds )
{
if (!vd.isPresent())
continue;
if (!transformsForData.containsKey( vd ))
continue;
final ViewRegistration vr = data.getViewRegistrations().getViewRegistration( vd );
final ViewTransform vtCalib = vr.getTransformList().get( vr.getTransformList().size() - 1 );
final AffineTransform3D calib = new AffineTransform3D();
calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() );
vr.getTransformList().clear();
vr.preconcatenateTransform( vtCalib );
final AffineTransform3D tr = new AffineTransform3D();
tr.set( transformsForData.get( vd ).getRowPackedCopy() );
ViewTransformAffine vtTC = new ViewTransformAffine( "Translation from Tile Configuration", tr );
vr.preconcatenateTransform( vtTC );
if (keepRotation)
{
AffineTransform3D rotation = new AffineTransform3D();
Pair< Double, Integer > rotAngleAndAxis = RegularTranformHelpers.getRoatationFromMetadata( vd.getViewSetup().getAttribute( Angle.class ) );
if (rotAngleAndAxis != null)
{
rotation.rotate( rotAngleAndAxis.getB(), rotAngleAndAxis.getA() );
vr.preconcatenateTransform( new ViewTransformAffine( "Rotation from Metadata", rotation.copy() ));
}
}
vr.updateModel();
}
}
示例5: updateBDVPreview
import net.imglib2.realtransform.AffineTransform3D; //导入方法依赖的package包/类
public static void updateBDVPreview(Map<ViewId, Translation3D> locations, boolean pixelUnits, boolean keepRotation,
AbstractSpimData< ? > data, BigDataViewer bdv)
{
if (data == null || bdv == null )
return;
final Map< ViewId, Translation3D > transformsForData = getTransformsForData( locations, pixelUnits, data );
final Collection< BasicViewDescription< ? > > vds = (Collection< BasicViewDescription< ? > >) data.getSequenceDescription().getViewDescriptions().values();
final int currentTPId = data.getSequenceDescription().getTimePoints().getTimePointsOrdered()
.get( bdv.getViewer().getState().getCurrentTimepoint() ).getId();
for ( BasicViewDescription< ? > vd : vds )
{
if (vd.getTimePointId() != currentTPId)
continue;
final int sourceIdx = StitchingExplorerPanel.getBDVSourceIndex( vd.getViewSetup(), data );
final SourceState< ? > s = bdv.getViewer().getState().getSources().get( sourceIdx );
final ViewRegistration vr = data.getViewRegistrations().getViewRegistration( vd );
final AffineTransform3D inv = vr.getModel().copy().inverse();
final AffineTransform3D calib = new AffineTransform3D();
calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() );
AffineTransform3D transform;
if (transformsForData.containsKey( vd ))
{
transform = inv.copy().preConcatenate( calib ).preConcatenate( transformsForData.get( vd ) );
}
else
continue;
if (keepRotation)
{
AffineTransform3D rotation = new AffineTransform3D();
Pair< Double, Integer > rotAngleAndAxis = RegularTranformHelpers.getRoatationFromMetadata( vd.getViewSetup().getAttribute( Angle.class ) );
if (rotAngleAndAxis != null)
{
rotation.rotate( rotAngleAndAxis.getB(), rotAngleAndAxis.getA() );
transform.preConcatenate( rotation.copy() );
}
}
( (TransformedSource< ? >) s.getSpimSource() ).setFixedTransform( transform );
}
bdv.getViewer().requestRepaint();
}
示例6: main
import net.imglib2.realtransform.AffineTransform3D; //导入方法依赖的package包/类
final static public void main( final String[] args )
throws ImgIOException
{
new ImageJ();
final ImgOpener io = new ImgOpener();
//final RandomAccessibleInterval< UnsignedShortType > img = io.openImg( "/home/saalfeld/phd/light-microscopy/presentation/saalfeld-05-05-4-DPX-05_L1_Sum.lsm", new ArrayImgFactory< UnsignedShortType >(), new UnsignedShortType());
final ImgPlus< UnsignedShortType > imgPlus = io.openImg( "/home/saalfeld/Desktop/l1-cns.tif", new ArrayImgFactory< UnsignedShortType >(), new UnsignedShortType());
// TODO - using averageScale() introduces error for nonlinear axes
final double scale0 = imgPlus.averageScale(0);
final double scale1 = imgPlus.averageScale(1);
final double[][] matrix = new double[][]{
{ 0.5, 0, 0, imgPlus.dimension( 0 ) * 0.25 },
{ 0, 0.5 * scale1 / scale0, 0, imgPlus.dimension(1) * 0.25 },
// TODO - this scale code is how it was before average() code
// added. Might be a bug. Review.
{ 0, 0, 0.5 * scale0 / scale0, 0 }
};
// final AffineTransform affine = new AffineTransform( new Matrix( matrix ) );
final AffineTransform3D affine = new AffineTransform3D();
affine.set( matrix[ 0 ][ 0 ], matrix[ 0 ][ 1 ], matrix[ 0 ][ 2 ], matrix[ 0 ][ 3 ], matrix[ 1 ][ 0 ], matrix[ 1 ][ 1 ], matrix[ 1 ][ 2 ], matrix[ 1 ][ 3 ], matrix[ 2 ][ 0 ], matrix[ 2 ][ 1 ], matrix[ 2 ][ 2 ], matrix[ 2 ][ 3 ] );
// final InterpolatorFactory< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolatorFactory = new NearestNeighborInterpolatorFactory< UnsignedShortType >();
// final InterpolatorFactory< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolatorFactory = new NLinearInterpolatorFactory< UnsignedShortType >();
final InterpolatorFactory< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolatorFactory = new LanczosInterpolatorFactory< UnsignedShortType >();
final RandomAccessible< UnsignedShortType > extendedImg = Views.extendValue( imgPlus, new UnsignedShortType() );
final Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > > interpolant = new Interpolant< UnsignedShortType, RandomAccessible< UnsignedShortType > >( extendedImg, interpolatorFactory );
final AffineRandomAccessible< UnsignedShortType, AffineGet > mapping = new AffineRandomAccessible< UnsignedShortType, AffineGet >( interpolant, affine );
final ARGBScreenImage screenImage = new ARGBScreenImage( ( int )imgPlus.dimension( 0 ), ( int )imgPlus.dimension( 1 ) );
final IterableIntervalProjector2D< UnsignedShortType, ARGBType > projector = new IterableIntervalProjector2D< UnsignedShortType, ARGBType >( 0, 1, mapping, screenImage, new RealARGBConverter< UnsignedShortType >( 0, 4095 ) );
final ColorProcessor cp = new ColorProcessor( screenImage.image() );
final ImagePlus imp = new ImagePlus( "argbScreenProjection", cp );
imp.show();
final Timer timer = new Timer();
projector.setPosition( imgPlus.dimension( 2 ) / 2, 2 );
final AffineTransform3D forward = new AffineTransform3D();
final AffineTransform3D rotation = new AffineTransform3D();
final AffineTransform3D scale = new AffineTransform3D();
scale.set(
4, 0, 0, 0,
0, 4, 0, 0,
0, 0, 4, 0 );
for ( int k = 0; k < 3; ++k )
{
timer.start();
for ( int i = 45; i < 48; ++i )
{
rotation.rotate( 1, Math.PI / 360 );
forward.set(
1.0, 0, 0, -imgPlus.dimension( 0 ) / 2.0,
0, 1.0, 0, -imgPlus.dimension( 1 ) / 2.0,
0, 0, 1.0, -imgPlus.dimension( 2 ) / 2.0 );
forward.preConcatenate( scale );
forward.preConcatenate( rotation );
forward.set(
forward.get( 0, 0 ), forward.get( 0, 1 ), forward.get( 0, 2 ), forward.get( 0, 3 ) + imgPlus.dimension( 0 ) / 2.0,
forward.get( 1, 0 ), forward.get( 1, 1 ), forward.get( 1, 2 ), forward.get( 1, 3 ) + imgPlus.dimension( 1 ) / 2.0,
forward.get( 2, 0 ), forward.get( 2, 1 ), forward.get( 2, 2 ), forward.get( 2, 3 ) + imgPlus.dimension( 2 ) / 2.0 );
affine.set( forward.inverse() );
projector.map();
imp.setImage( screenImage.image() );
}
IJ.log( "loop " + ( k + 1 ) + ": " + timer.stop() );
}
final ColorProcessor cpa = new ColorProcessor( screenImage.image() );
imp.setProcessor( cpa );
imp.updateAndDraw();
}