mpicbg.imglib.type.numeric.RealType Java Examples

The following examples show how to use mpicbg.imglib.type.numeric.RealType. 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: PairWiseStitchingImgLib.java    From Stitching with GNU General Public License v2.0 6 votes vote down vote up
public static < T extends RealType<T>, S extends RealType<S> > PairWiseStitchingResult performStitching( final Image<T> img1, final Image<S> img2, final StitchingParameters params )
{
	if ( img1 == null )
	{
		Log.error( "Image 1 could not be wrapped." );
		return null;
	}
	else if ( img2 == null )
	{
		Log.error( "Image 2 could not be wrapped." );
		return null;
	}
	else if ( params == null )
	{
		Log.error( "Parameters are null." );
		return null;
	}
	
	final PairWiseStitchingResult result = computePhaseCorrelation( img1, img2, params.checkPeaks, params.subpixelAccuracy );
	
	return result;
}
 
Example #2
Source File: DetectionSegmentation.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static <T extends RealType<T>> ArrayList< DifferenceOfGaussianPeak<T> > extractBeadsLaPlaceImgLib( 
final Image<T> img,
final OutOfBoundsStrategyFactory<T> oobsFactory,
final float imageSigma, 
final float initialSigma,
float minPeakValue,
float minInitialPeakValue,
final int stepsPerOctave,
final boolean findMax,
final boolean findMin,
final int debugLevel )
     	{
final float k = (float)computeK( stepsPerOctave );
final float sigma1 = initialSigma;
final float sigma2 = initialSigma * k;

return extractBeadsLaPlaceImgLib(img, oobsFactory, imageSigma, sigma1, sigma2, minPeakValue, minInitialPeakValue, findMax, findMin, debugLevel );
     	}
 
Example #3
Source File: DetectionSegmentation.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static <T extends RealType<T>> ArrayList< DifferenceOfGaussianPeak<T> > extractBeadsLaPlaceImgLib( 
		final Image<T> img,
		final float initialSigma,
		float minPeakValue,
		float minInitialPeakValue )
{
	return extractBeadsLaPlaceImgLib(img, new OutOfBoundsStrategyMirrorFactory<T>(), 0.5f, initialSigma, minPeakValue, minInitialPeakValue, 4, true, false, ViewStructure.DEBUG_MAIN );
}
 
Example #4
Source File: PhaseCorrelationCalculator.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public <T extends RealType<T>, S extends RealType<S>> PhaseCorrelationCalculator( ImagePlus imp1, ImagePlus imp2 )
{
	Image<T> img1 = ImagePlusAdapter.wrap( imp1 );
	Image<S> img2 = ImagePlusAdapter.wrap( imp2 );
	
	PhaseCorrelation<T, S> phase = new PhaseCorrelation<T, S>( img1, img2 );
	
	if ( !phase.checkInput() || !phase.process() )
	{
		System.out.println( phase.getErrorMessage() );
	}
	
	peak = phase.getShift();
}
 
Example #5
Source File: PairWiseStitchingImgLib.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
public static < T extends RealType<T>, S extends RealType<S> > PairWiseStitchingResult computePhaseCorrelation( final Image<T> img1, final Image<S> img2, final int numPeaks, final boolean subpixelAccuracy )
{
	final PhaseCorrelation< T, S > phaseCorr = new PhaseCorrelation<T, S>( img1, img2 );
	phaseCorr.setInvestigateNumPeaks( numPeaks );
	
	if ( subpixelAccuracy )
		phaseCorr.setKeepPhaseCorrelationMatrix( true );
	
	phaseCorr.setComputeFFTinParalell( true );
	if ( !phaseCorr.process() )
	{
		Log.error( "Could not compute phase correlation: " + phaseCorr.getErrorMessage() );
		return null;
	}

	// result
	final PhaseCorrelationPeak pcp = phaseCorr.getShift();
	final float[] shift = new float[ img1.getNumDimensions() ];
	final PairWiseStitchingResult result;
	
	if ( subpixelAccuracy )
	{
		final Image<FloatType> pcm = phaseCorr.getPhaseCorrelationMatrix();		
	
		final ArrayList<DifferenceOfGaussianPeak<FloatType>> list = new ArrayList<DifferenceOfGaussianPeak<FloatType>>();		
		final Peak p = new Peak( pcp );
		list.add( p );
				
		final SubpixelLocalization<FloatType> spl = new SubpixelLocalization<FloatType>( pcm, list );
		final boolean move[] = new boolean[ pcm.getNumDimensions() ];
		for ( int i = 0; i < pcm.getNumDimensions(); ++i )
			move[ i ] = false;
		spl.setCanMoveOutside( true );
		spl.setAllowedToMoveInDim( move );
		spl.setMaxNumMoves( 0 );
		spl.setAllowMaximaTolerance( false );
		spl.process();
		
		final Peak peak = (Peak)list.get( 0 );
		
		for ( int d = 0; d < img1.getNumDimensions(); ++d )
			shift[ d ] = peak.getPCPeak().getPosition()[ d ] + peak.getSubPixelPositionOffset( d );
		
		pcm.close();
		
		result = new PairWiseStitchingResult( shift, pcp.getCrossCorrelationPeak(), p.getValue().get() );
	}
	else
	{
		for ( int d = 0; d < img1.getNumDimensions(); ++d )
			shift[ d ] = pcp.getPosition()[ d ];
		
		result = new PairWiseStitchingResult( shift, pcp.getCrossCorrelationPeak(), pcp.getPhaseCorrelationPeak() );
	}
	
	return result;
}
 
Example #6
Source File: PairWiseStitchingImgLib.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
/**
 * return an {@code Image<T>} as input for the PhaseCorrelation.
 * 
 * @param imp - the {@link ImagePlus}
 * @param imgFactory - the {@link ImageFactory} defining wher to put it into
 * @param channel - which channel (if channel=0 means average all channels)
 * @param timepoint - which timepoint
 * 
 * @return - the {@link Image} or null if it was not an ImagePlus.GRAY8, ImagePlus.GRAY16 or ImagePlus.GRAY32
 */
public static < T extends RealType<T> > Image<T> getImage( final ImagePlus imp, Roi roi, final ImageFactory<T> imgFactory, final int channel, final int timepoint )
{
	// first test the roi
	roi = getOnlyRectangularRoi( roi );
	
	// how many dimensions?
	final int numDimensions;		
	if ( imp.getNSlices() > 1 )
		numDimensions = 3;
	else
		numDimensions = 2;
	
	// the size of the image
	final int[] size = new int[ numDimensions ];
	final int[] offset = new int[ numDimensions ];
	
	if ( roi == null )
	{
		size[ 0 ] = imp.getWidth();
		size[ 1 ] = imp.getHeight();
		
		if ( numDimensions == 3 )
			size[ 2 ] = imp.getNSlices();
	}
	else
	{
		size[ 0 ] = roi.getBounds().width;
		size[ 1 ] = roi.getBounds().height;

		offset[ 0 ] = roi.getBounds().x;
		offset[ 1 ] = roi.getBounds().y;
		
		if ( numDimensions == 3 )
			size[ 2 ] = imp.getNSlices();
	}
	
	// create the Image
	final Image<T> img = imgFactory.createImage( size );
	final boolean success;
	
	// copy the content
	if ( channel == 0 )
	{
		// we need to average all channels
		success = averageAllChannels( img, offset, imp, timepoint );
	}
	else
	{
		// otherwise only copy one channel
		success = fillInChannel( img, offset, imp, channel, timepoint );
	}
	
	if ( success )
	{
		return img;
	}
	img.close();
	return null;
}
 
Example #7
Source File: PairWiseStitchingImgLib.java    From Stitching with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Averages all channels into the target image. The size is given by the dimensions of the target image,
 * the offset (if applicable) is given by an extra field
 * 
 * @param target - the target Image
 * @param offset - the offset of the area (might be [0,0] or [0,0,0])
 * @param sources - a list of input Images
 */
protected static < T extends RealType< T >, S extends RealType< S > > void averageAllChannels( final Image< T > target, final ArrayList< Image< S > > sources, final int[] offset )
{
	// get the major numbers
	final int numDimensions = target.getNumDimensions();
	final float numImages = sources.size();
	long imageSize = target.getDimension( 0 );
	
	for ( int d = 1; d < target.getNumDimensions(); ++d )
		imageSize *= target.getDimension( 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();
               	
           		// the cursor for the output
           		final LocalizableCursor< T > targetCursor =  target.createLocalizableCursor();
           		
           		// the input cursors
           		final ArrayList< LocalizableByDimCursor< S > > sourceCursors = new ArrayList< LocalizableByDimCursor< S > > ();
           		
           		for ( final Image< S > source : sources )
           			sourceCursors.add( source.createLocalizableByDimCursor() );
           		
           		// temporary array
           		final int[] location = new int[ numDimensions ]; 

           		// move to the starting position of the current thread
           		targetCursor.fwd( startPos );
                   
           		// do as many pixels as wanted by this thread
                   for ( long j = 0; j < loopSize; ++j )
           		{
           			targetCursor.fwd();
           			targetCursor.getPosition( location );
           			
           			for ( int d = 0; d < numDimensions; ++d )
           				location[ d ] += offset[ d ];
           			
           			float sum = 0;
           			
           			for ( final LocalizableByDimCursor< S > sourceCursor : sourceCursors )
           			{
           				sourceCursor.setPosition( location );
           				sum += sourceCursor.getType().getRealFloat();
           			}
           			
           			targetCursor.getType().setReal( sum / numImages );
           		}                	
               }
           });
       
       SimpleMultiThreading.startAndJoin( threads );		
}
 
Example #8
Source File: MCTriangulator.java    From TrakEM2 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @param img The {@code Image<? extends RealType>} instance to use.
 * @param threshold The cut-off (inclusive) of pixel values considered inside.
 * @param origin The translation of the origin, in 3D.
 */
public<T extends RealType<T>> List<Point3f> getTriangles(final Image<T> img, final int threshold, final float[] origin) throws Exception {
	return MCCube.getTriangles(new ImgLibVolume(img, origin), threshold);
}