mpicbg.models.InvertibleCoordinateTransform Java Examples

The following examples show how to use mpicbg.models.InvertibleCoordinateTransform. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OverlayFusion.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Fuse one slice/volume (one channel)
 * 
 * @param output - same the type of the ImagePlus input
 * @param input - FloatType, because of Interpolation that needs to be done
 * @param transform - the transformation
 */
protected static <T extends RealType<T>> void fuseChannel( final Img<T> output, final RealRandomAccessible<FloatType> input, final double[] offset, final InvertibleCoordinateTransform transform )
{
	final int dims = output.numDimensions();
	long imageSize = output.dimension( 0 );
	
	for ( int d = 1; d < output.numDimensions(); ++d )
		imageSize *= output.dimension( d );

	// run multithreaded
	final AtomicInteger ai = new AtomicInteger(0);					
       final Thread[] threads = SimpleMultiThreading.newThreads();

       final Vector<Chunk> threadChunks = SimpleMultiThreading.divideIntoChunks( imageSize, threads.length );
       
       for (int ithread = 0; ithread < threads.length; ++ithread)
           threads[ithread] = new Thread(new Runnable()
           {
               @Override
               public void run()
               {
               	// Thread ID
               	final int myNumber = ai.getAndIncrement();
       
               	// get chunk of pixels to process
               	final Chunk myChunk = threadChunks.get( myNumber );
               	final long startPos = myChunk.getStartPosition();
               	final long loopSize = myChunk.getLoopSize();
               	
           		final Cursor<T> out = output.localizingCursor();
           		final RealRandomAccess<FloatType> in = input.realRandomAccess();
           		
           		final double[] tmp = new double[ input.numDimensions() ];
           		
           		try 
           		{
               		// move to the starting position of the current thread
           			out.jumpFwd( startPos );
           			
               		// do as many pixels as wanted by this thread
                       for ( long j = 0; j < loopSize; ++j )
                       {
           				out.fwd();
           				
           				for ( int d = 0; d < dims; ++d )
           					tmp[ d ] = out.getDoublePosition( d ) + offset[ d ];
           				
           				transform.applyInverseInPlace( tmp );
           	
           				in.setPosition( tmp );
           				out.get().setReal( in.get().get() );
           			}
           		} 
           		catch (NoninvertibleModelException e) 
           		{
           			Log.error( "Cannot invert model, qutting." );
           			return;
           		}

               }
           });
       
       SimpleMultiThreading.startAndJoin( threads );
	
       /*
	final LocalizableCursor<T> out = output.createLocalizableCursor();
	final Interpolator<FloatType> in = input.createInterpolator( factory );
	
	final float[] tmp = new float[ input.getNumDimensions() ];
	
	try 
	{
		while ( out.hasNext() )
		{
			out.fwd();
			
			for ( int d = 0; d < dims; ++d )
				tmp[ d ] = out.getPosition( d ) + offset[ d ];
			
			transform.applyInverseInPlace( tmp );

			in.setPosition( tmp );			
			out.getType().setReal( in.getType().get() );
		}
	} 
	catch (NoninvertibleModelException e) 
	{
		Log.error( "Cannot invert model, qutting." );
		return;
	}
	*/
}
 
Example #2
Source File: BlockMatchPairCallable.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public BlockMatchResults call() throws Exception
    {
        final ArrayList< PointMatch > pm12 = new ArrayList< PointMatch >();
        final ArrayList< PointMatch > pm21 = new ArrayList< PointMatch >();

        System.out.println("BMC rev 0: " + pair.a + " " + pair.b);

        final Pair< FloatProcessor, FloatProcessor > pair1 = makeFlatImage( layer1, AlignmentUtils.filterPatches( layer1, filter ), box, param.layerScale );
        final Pair< FloatProcessor, FloatProcessor > pair2 = makeFlatImage( layer2, AlignmentUtils.filterPatches( layer2, filter ), box, param.layerScale );
        
        final FloatProcessor ip1 = pair1.a;
        final FloatProcessor ip1Mask = pair1.b;
        final FloatProcessor ip2 = pair2.a;
        final FloatProcessor ip2Mask = pair2.b;
        
        final AbstractModel< ? > localSmoothnessFilterModel =
                Util.createModel(param.localModelIndex);

        final int blockRadius =
                Math.max( 16, mpicbg.util.Util.roundPos( param.layerScale * param.blockRadius ) );

        /* scale pixel distances */
        final int searchRadius = ( int )Math.round( param.layerScale * param.searchRadius );
        final double localRegionSigma = param.layerScale * param.localRegionSigma;
        final double maxLocalEpsilon = param.layerScale * param.maxLocalEpsilon;

        if (!layer1Fixed)
        {


            BlockMatching.matchByMaximalPMCC(
                    ip1,
                    ip2,
                    ip1Mask,
                    ip2Mask,
                    1.0,
                    ((InvertibleCoordinateTransform) pair.c).createInverse(),
                    blockRadius,
                    blockRadius,
                    searchRadius,
                    searchRadius,
                    param.minR,
                    param.rodR,
                    param.maxCurvatureR,
                    v1,
                    pm12,
                    new ErrorStatistic(1));

            if ( Thread.interrupted() )
            {
                throw new InterruptedException("Block matching interrupted.");
            }

            if ( param.useLocalSmoothnessFilter )
            {
                localSmoothnessFilterModel.localSmoothnessFilter( pm12, pm12, localRegionSigma,
                        maxLocalEpsilon, param.maxLocalTrust );
            }
        }

        if (!layer2Fixed)
        {
            BlockMatching.matchByMaximalPMCC(
                    ip2,
                    ip1,
                    ip2Mask,
                    ip1Mask,
                    1.0f,
                    pair.c,
                    blockRadius,
                    blockRadius,
                    searchRadius,
                    searchRadius,
                    param.minR,
                    param.rodR,
                    param.maxCurvatureR,
                    v2,
                    pm21,
                    new ErrorStatistic( 1 ) );

            if ( Thread.interrupted() )
            {
                throw new InterruptedException("Block matching interrupted.");
            }

            if ( param.useLocalSmoothnessFilter )
            {
                localSmoothnessFilterModel.localSmoothnessFilter( pm21, pm21, localRegionSigma, maxLocalEpsilon, param.maxLocalTrust );
            }
        }

//        Utils.log( pair.a + " <> " + pair.b + " spring constant = " + springConstant );


        return new BlockMatchResults(v1, v2, pm12, pm21, layer1Fixed, layer2Fixed, pair);
    }