Java Code Examples for mpicbg.imglib.image.Image#createCursor()

The following examples show how to use mpicbg.imglib.image.Image#createCursor() . 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: BayesMVDeconvolution.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
private static final void computeQuotient( final long start, final long loopSize, final Image< FloatType > psiBlurred, final LRFFT processingData )
{
	final Cursor<FloatType> cursorImg = processingData.getImage().createCursor();
	final Cursor<FloatType> cursorPsiBlurred = psiBlurred.createCursor();
	
	cursorImg.fwd( start );
	cursorPsiBlurred.fwd( start );
	
	for ( long l = 0; l < loopSize; ++l )
	{
		cursorImg.fwd();
		cursorPsiBlurred.fwd();
		
		final float imgValue = cursorImg.getType().get();
		final float psiBlurredValue = cursorPsiBlurred.getType().get();
		
		cursorPsiBlurred.getType().set( imgValue / psiBlurredValue );
	}
	
	cursorImg.close();
	cursorPsiBlurred.close();
	
}
 
Example 2
Source File: LucyRichardsonMultiViewDeconvolution.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
final private static BigDecimal sumImage( final Image<FloatType> img )
{
	BigDecimal sum = new BigDecimal( 0, MathContext.UNLIMITED );
	
	final Cursor<FloatType> cursorImg = img.createCursor();
	
	while ( cursorImg.hasNext() )
	{
		cursorImg.fwd();
		sum = sum.add( BigDecimal.valueOf( (double)cursorImg.getType().get() ) );
	}
	
	cursorImg.close();

	return sum;
}
 
Example 3
Source File: LucyRichardsonMultiViewDeconvolution.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
final private static void normImage( final Image<FloatType> img )
{
	final BigDecimal sum = sumImage( img );	
	
	final Cursor<FloatType> cursor = img.createCursor();
				
	while ( cursor.hasNext() )
	{
		cursor.fwd();
		cursor.getType().set( (float) ((double)cursor.getType().get() / sum.doubleValue()) );
	}
	
	cursor.close();		
}
 
Example 4
Source File: DOM.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static Image< FloatType > computeContentBasedWeighting( final Image< FloatType > img, final int fusionSigma1, final int fusionSigma2, final float zStretching )
{
	// compute the radii
	final int rxy1 = Math.round( fusionSigma1 );
	final int rxy2 = Math.round( fusionSigma2 );

	final int rz1 = Math.round( fusionSigma1 / zStretching );
	final int rz2 = Math.round( fusionSigma2 / zStretching );
				
	// compute I*sigma1, store in imgConv
	final Image< LongType > integralImg = IntegralImage3d.compute( img );
	final Image< FloatType > imgConv = img.createNewImage();			
	DOM.meanMirror( integralImg, imgConv, rxy1*2 + 1, rxy1*2 + 1, rz1*2 + 1 );
	
	// compute ( I - I*sigma1 )^2, store in imgConv
	final Cursor<FloatType> cursorImg = img.createCursor();
	final Cursor<FloatType> cursorConv = imgConv.createCursor();
	
	while ( cursorImg.hasNext() )
	{
		cursorImg.fwd();
		cursorConv.fwd();
		
		final float diff = cursorImg.getType().get() - cursorConv.getType().get();
		
		cursorConv.getType().set( diff*diff );
	}
	
	// compute ( ( I - I*sigma1 )^2 ) * sigma2, store in imgConv
	IntegralImage3d.computeIntegralImage( integralImg, imgConv );
	
	DOM.meanMirror( integralImg, imgConv, rxy2*2 + 1, rxy2*2 + 1, rz2*2 + 1 );
	
	integralImg.close();
	
	ViewDataBeads.normalizeImage( imgConv );
	
	return imgConv;
}
 
Example 5
Source File: BayesMVDeconvolution.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
private static final void computeFinalValues( final long start, final long loopSize, final Image< FloatType > psi, final Image<FloatType> integral, final Image<FloatType> weight, final double lambda )
{
	final Cursor< FloatType > cursorPsi = psi.createCursor();
	final Cursor< FloatType > cursorIntegral = integral.createCursor();
	final Cursor< FloatType > cursorWeight = weight.createCursor();
	
	cursorPsi.fwd( start );
	cursorIntegral.fwd( start );
	cursorWeight.fwd( start );
	
	for ( long l = 0; l < loopSize; ++l )
	{
		cursorPsi.fwd();
		cursorIntegral.fwd();
		cursorWeight.fwd();
		
		final float lastPsiValue = cursorPsi.getType().get();
		
		float value = lastPsiValue * cursorIntegral.getType().get();

		if ( value > 0 )
		{
			//
			// perform Tikhonov regularization if desired
			//		
			if ( lambda > 0 )
				value = ( (float)( (Math.sqrt( 1.0 + 2.0*lambda*value ) - 1.0) / lambda ) );
		}
		else
		{
			value = minValue;
		}
		//
		// get the final value and some statistics
		//
		float nextPsiValue;
		
		if ( Double.isNaN( value ) )
			nextPsiValue = (float)minValue;
		else
			nextPsiValue = (float)Math.max( minValue, value );
		
		// compute the difference between old and new
		float change = nextPsiValue - lastPsiValue;				
		
		// apply the apropriate amount
		change *= cursorWeight.getType().get();
		nextPsiValue = lastPsiValue + change;

		// store the new value
		cursorPsi.getType().set( (float)nextPsiValue );
	}		
}
 
Example 6
Source File: DOM.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static Image<FloatType> computeContentBasedGauss( final Image< FloatType > img, final int fusionSigma1, final int fusionSigma2, final float zStretching )
{
	// get the kernels			
	final double[] k1 = new double[ img.getNumDimensions() ];
	final double[] k2 = new double[ img.getNumDimensions() ];
	
	for ( int d = 0; d < img.getNumDimensions() - 1; ++d )
	{
		k1[ d ] = fusionSigma1;
		k2[ d ] = fusionSigma2;
	}
	
	k1[ img.getNumDimensions() - 1 ] = fusionSigma1 / zStretching;
	k2[ img.getNumDimensions() - 1 ] = fusionSigma2 / zStretching;		
	
	final Image<FloatType> kernel1 = FourierConvolution.createGaussianKernel( new ArrayContainerFactory(), k1 );
	final Image<FloatType> kernel2 = FourierConvolution.createGaussianKernel( new ArrayContainerFactory(), k2 );

	System.out.println( new Date( System.currentTimeMillis() )  + " conv1" );
	
	// compute I*sigma1
	FourierConvolution<FloatType, FloatType> fftConv1 = new FourierConvolution<FloatType, FloatType>( img, kernel1 );
	
	fftConv1.process();		
	final Image<FloatType> conv1 = fftConv1.getResult();
	
	fftConv1.close();
	fftConv1 = null;

	System.out.println( new Date( System.currentTimeMillis() )  + " comp" );

	// compute ( I - I*sigma1 )^2
	final Cursor<FloatType> cursorImg = img.createCursor();
	final Cursor<FloatType> cursorConv = conv1.createCursor();
	
	while ( cursorImg.hasNext() )
	{
		cursorImg.fwd();
		cursorConv.fwd();
		
		final float diff = cursorImg.getType().get() - cursorConv.getType().get();
		
		cursorConv.getType().set( diff*diff );
	}

	System.out.println( new Date( System.currentTimeMillis() )  + " conv2" );

	// compute ( ( I - I*sigma1 )^2 ) * sigma2
	FourierConvolution<FloatType, FloatType> fftConv2 = new FourierConvolution<FloatType, FloatType>( conv1, kernel2 );
	fftConv2.process();	
	
	Image<FloatType> gaussContent = fftConv2.getResult();

	fftConv2.close();
	fftConv2 = null;
	
	// close the unnecessary image
	kernel1.close();
	kernel2.close();
	conv1.close();
	
	ViewDataBeads.normalizeImage( gaussContent );
	
	return gaussContent;
}
 
Example 7
Source File: GaussContent.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected GaussContent( final ViewDataBeads view, final ContainerFactory entropyContainer ) 
{
	super( view );
	
	try
	{			
		final SPIMConfiguration conf = view.getViewStructure().getSPIMConfiguration();
		
		// get the kernels			
		final double[] k1 = new double[ view.getNumDimensions() ];
		final double[] k2 = new double[ view.getNumDimensions() ];
		
		for ( int d = 0; d < view.getNumDimensions() - 1; ++d )
		{
			k1[ d ] = conf.fusionSigma1;
			k2[ d ] = conf.fusionSigma2;
		}
		
		k1[ view.getNumDimensions() - 1 ] = conf.fusionSigma1 / view.getZStretching();
		k2[ view.getNumDimensions() - 1 ] = conf.fusionSigma2 / view.getZStretching();		
		
		final Image<FloatType> kernel1 = FourierConvolution.createGaussianKernel( new ArrayContainerFactory(), k1 );
		final Image<FloatType> kernel2 = FourierConvolution.createGaussianKernel( new ArrayContainerFactory(), k2 );

		// compute I*sigma1
		FourierConvolution<FloatType, FloatType> fftConv1 = new FourierConvolution<FloatType, FloatType>( view.getImage(), kernel1 );
		
		fftConv1.process();		
		final Image<FloatType> conv1 = fftConv1.getResult();
		
		fftConv1.close();
		fftConv1 = null;
				
		// compute ( I - I*sigma1 )^2
		final Cursor<FloatType> cursorImg = view.getImage().createCursor();
		final Cursor<FloatType> cursorConv = conv1.createCursor();
		
		while ( cursorImg.hasNext() )
		{
			cursorImg.fwd();
			cursorConv.fwd();
			
			final float diff = cursorImg.getType().get() - cursorConv.getType().get();
			
			cursorConv.getType().set( diff*diff );
		}

		// compute ( ( I - I*sigma1 )^2 ) * sigma2
		FourierConvolution<FloatType, FloatType> fftConv2 = new FourierConvolution<FloatType, FloatType>( conv1, kernel2 );
		fftConv2.process();	
		
		gaussContent = fftConv2.getResult();

		fftConv2.close();
		fftConv2 = null;
		
		// close the unnecessary image
		kernel1.close();
		kernel2.close();
		conv1.close();
		
		ViewDataBeads.normalizeImage( gaussContent );
	}
	catch ( OutOfMemoryError e )
	{
		IJ.log( "OutOfMemory: Cannot compute Gauss approximated Entropy for " + view.getName() + ": " + e );
		e.printStackTrace();
		gaussContent = null;
	}
}
 
Example 8
Source File: AverageContent.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected AverageContent( final ViewDataBeads view, final ContainerFactory entropyContainer ) 
{
	super( view );
	
	try
	{			
		final SPIMConfiguration conf = view.getViewStructure().getSPIMConfiguration();
		
		// compute the radii
		final int rxy1 = Math.round( conf.fusionSigma1 );
		final int rxy2 = Math.round( conf.fusionSigma2 );

		final int rz1 = (int)Math.round( conf.fusionSigma1 / view.getZStretching() );
		final int rz2 = (int)Math.round( conf.fusionSigma2 / view.getZStretching() );

		// compute the integral image
		final Image< FloatType > img = view.getImage( false ); 
		
		if ( view.getViewStructure().getDebugLevel() <= ViewStructure.DEBUG_MAIN )
			IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Computing Integral Image");					
		/*
		final IntegralImageLong< FloatType > intImg = new IntegralImageLong<FloatType>( img, new Converter< FloatType, LongType >()
		{
			@Override
			public void convert( final FloatType input, final LongType output ) { output.set( Util.round( input.get() ) ); } 
		} 
		);
		
		intImg.process();
		
		final Image< LongType > integralImg = intImg.getResult();
		*/
					
		// compute I*sigma1, store in imgConv
		final Image< LongType > integralImg = IntegralImage3d.compute( img );
		final Image< FloatType > imgConv = img.createNewImage();			
		DOM.meanMirror( integralImg, imgConv, rxy1*2 + 1, rxy1*2 + 1, rz1*2 + 1 );
		
		// compute ( I - I*sigma1 )^2, store in imgConv
		final Cursor<FloatType> cursorImg = view.getImage().createCursor();
		final Cursor<FloatType> cursorConv = imgConv.createCursor();
		
		while ( cursorImg.hasNext() )
		{
			cursorImg.fwd();
			cursorConv.fwd();
			
			final float diff = cursorImg.getType().get() - cursorConv.getType().get();
			
			cursorConv.getType().set( diff*diff );
		}
		
		// compute ( ( I - I*sigma1 )^2 ) * sigma2, store in imgConv
		IntegralImage3d.computeIntegralImage( integralImg, imgConv );
		
		DOM.meanMirror( integralImg, imgConv, rxy2*2 + 1, rxy2*2 + 1, rz2*2 + 1 );
		
		integralImg.close();
		
		gaussContent = imgConv;
		
		ViewDataBeads.normalizeImage( gaussContent );
	}
	catch ( OutOfMemoryError e )
	{
		IJ.log( "OutOfMemory: Cannot compute Gauss approximated Entropy for " + view.getName() + ": " + e );
		e.printStackTrace();
		gaussContent = null;
	}
}