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

The following examples show how to use mpicbg.imglib.image.Image#setName() . 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: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public void extract( final int viewID, final int[] maxSize )
{
	final ArrayList<ViewDataBeads > views = viewStructure.getViews();
	final int numDimensions = 3;
	
	final int[] size;
	
	if ( this.size3d == null )
	{
		size = Util.getArrayFromValue( this.size, numDimensions );
		if ( !this.isotropic )
		{
			size[ numDimensions - 1 ] *= Math.max( 1, 5.0/views.get( 0 ).getZStretching() );
			if ( size[ numDimensions - 1 ] % 2 == 0 )
				size[ numDimensions - 1 ]++;
		}
	}
	else
	{
		size = this.size3d.clone();
	}
	
	IJ.log ( "PSF size: " + Util.printCoordinates( size ) );
	
	final ViewDataBeads view = views.get( viewID );		
		
	final Image<FloatType> originalPSF = extractPSF( view, size );
	final Image<FloatType> psf = transformPSF( originalPSF, (AbstractAffineModel3D<?>)view.getTile().getModel() );
	psf.setName( "PSF_" + view.getName() );
	
	for ( int d = 0; d < numDimensions; ++d )
		if ( psf.getDimension( d ) > maxSize[ d ] )
			maxSize[ d ] = psf.getDimension( d );
	
	pointSpreadFunctions.add( psf );
	originalPSFs.add( originalPSF );
	
	psf.getDisplay().setMinMax();
}
 
Example 2
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get projection along the smallest dimension (which is usually the rotation axis)
 * 
 * @return - the averaged, projected PSF
 */
public Image< FloatType > getMaxProjectionAveragePSF()
{
	final int[] dimensions = avgPSF.getDimensions();
	
	int minSize = dimensions[ 0 ];
	int minDim = 0;
	
	for ( int d = 0; d < dimensions.length; ++d )
	{
		if ( avgPSF.getDimension( d ) < minSize )
		{
			minSize = avgPSF.getDimension( d );
			minDim = d;
		}
	}
	
	final int[] projDim = new int[ dimensions.length - 1 ];
	
	int dim = 0;
	int sizeProjection = 0;
	
	// the new dimensions
	for ( int d = 0; d < dimensions.length; ++d )
		if ( d != minDim )
			projDim[ dim++ ] = dimensions[ d ];
		else
			sizeProjection = dimensions[ d ];
	
	final Image< FloatType > proj = avgPSF.getImageFactory().createImage( projDim );
	
	final LocalizableByDimCursor< FloatType > psfIterator = avgPSF.createLocalizableByDimCursor();
	final LocalizableCursor< FloatType > projIterator = proj.createLocalizableCursor();
	
	final int[] tmp = new int[ avgPSF.getNumDimensions() ];
	
	while ( projIterator.hasNext() )
	{
		projIterator.fwd();

		dim = 0;
		for ( int d = 0; d < dimensions.length; ++d )
			if ( d != minDim )
				tmp[ d ] = projIterator.getPosition( dim++ );

		tmp[ minDim ] = -1;
		
		float maxValue = -Float.MAX_VALUE;
		
		psfIterator.setPosition( tmp );
		for ( int i = 0; i < sizeProjection; ++i )
		{
			psfIterator.fwd( minDim );
			final float value = psfIterator.getType().get();
			
			if ( value > maxValue )
				maxValue = value;
		}
		
		projIterator.getType().set( maxValue );
	}
	
	proj.setName( "MIP of PSF's of " + viewStructure.getID() );
	
	return proj;
}
 
Example 3
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public void extract()
{
	final ArrayList<ViewDataBeads > views = viewStructure.getViews();
	final int numDimensions = 3;
	
	final int[] size;
	if ( this.size3d == null )
	{
		size = Util.getArrayFromValue( this.size, numDimensions );
	
		if ( !this.isotropic )
		{
			size[ numDimensions - 1 ] *= Math.max( 1, 5.0/views.get( 0 ).getZStretching() );
			if ( size[ numDimensions - 1 ] % 2 == 0 )
				size[ numDimensions - 1 ]++;
		}
	}
	else
	{
		size = this.size3d.clone();
	}
	
	IJ.log ( "PSF size: " + Util.printCoordinates( size ) );
	
	final int[] maxSize = new int[ numDimensions ];
	
	for ( int d = 0; d < numDimensions; ++d )
		maxSize[ d ] = 0;
	
	for ( final ViewDataBeads view : views )		
	{
		final Image<FloatType> originalPSF = extractPSF( view, size );
		final Image<FloatType> psf = transformPSF( originalPSF, (AbstractAffineModel3D<?>)view.getTile().getModel() );
		psf.setName( "PSF_" + view.getName() );
		
		for ( int d = 0; d < numDimensions; ++d )
			if ( psf.getDimension( d ) > maxSize[ d ] )
				maxSize[ d ] = psf.getDimension( d );
		
		pointSpreadFunctions.add( psf );
		originalPSFs.add( originalPSF );
		
		psf.getDisplay().setMinMax();
	}
	
	computeAveragePSF( maxSize );
}
 
Example 4
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static ExtractPSF loadAndTransformPSF( final ArrayList< String > fileName, final boolean transformPSFs, final ViewStructure viewStructure )
{
	ExtractPSF extractPSF = new ExtractPSF( viewStructure );
	
	final ArrayList<ViewDataBeads > views = viewStructure.getViews();
	final int numDimensions = 3;
			
	final int[] maxSize = new int[ numDimensions ];
	
	for ( int d = 0; d < numDimensions; ++d )
		maxSize[ d ] = 0;

	int i = 0;
	for ( final ViewDataBeads view : views )		
	{
        // extract the PSF for this one	        
   		if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
   			IOFunctions.println( "Loading PSF file '" + fileName.get( i ) + "' for " + view.getName() );

		final Image< FloatType > psfImage = LOCI.openLOCIFloatType( fileName.get( i ), viewStructure.getSPIMConfiguration().inputImageFactory );
		
		if ( psfImage == null )
		{
			IJ.log( "Could not find PSF file '" + fileName.get( i ) + "' - quitting." );
			return null;
		}
		
		++i;

		final Image<FloatType> psf;
		
		if ( transformPSFs )
		{
			if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
				IOFunctions.println( "Transforming PSF for " + view.getName() );

			psf = transformPSF( psfImage, (AbstractAffineModel3D<?>)view.getTile().getModel() );
		}
		else
		{
			psf = psfImage.clone();
		}
		
		psf.setName( "PSF_" + view.getName() );
		
		for ( int d = 0; d < numDimensions; ++d )
			if ( psf.getDimension( d ) > maxSize[ d ] )
				maxSize[ d ] = psf.getDimension( d );
		
		extractPSF.pointSpreadFunctions.add( psf );
		extractPSF.originalPSFs.add( psfImage );
		
		psf.getDisplay().setMinMax();
	}
	
	extractPSF.computeAveragePSF( maxSize );
	
	return extractPSF;
}
 
Example 5
Source File: BeadSegmentation.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public void segment( final SPIMConfiguration conf, final ArrayList<ViewDataBeads> views )
{
	final double threshold = conf.threshold;
			
	//
	// Extract the beads
	// 		
	for ( final ViewDataBeads view : views )
	{
		if ( conf.segmentation == SegmentationTypes.DOG )					
		{
    		if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
    			IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Starting Scale Space Bead Extraction for " + view.getName() );
			
    		view.setBeadStructure( extractBeadsLaPlaceImgLib( view, conf ) );
    		
    		if ( debugBeads )
    		{
				Image<FloatType> img = getFoundBeads( view );				
				img.setName( "imglib" );
				img.getDisplay().setMinMax();
				ImageJFunctions.copyToImagePlus( img ).show();				
				SimpleMultiThreading.threadHaltUnClean();		    			
    		}
		}
		else if ( conf.segmentation == SegmentationTypes.THRESHOLD )
		{
    		if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
    			IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Starting Threshold Bead Extraction for " + view.getName() );				
			
			view.setBeadStructure( extractBeadsThresholdSegmentation( view, (float)threshold, conf.minSize, conf.maxSize, conf.minBlackBorder) );
		}
		else if ( conf.segmentation == SegmentationTypes.DOM )
		{
    		if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
    			IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Starting Integral Image based DOM Bead Extraction for " + view.getName() );
    		
			view.setBeadStructure( extractBeadsDOM( view, conf ) );
		}
		else
		{
			throw new RuntimeException( "Unknown segmentation: " + conf.segmentation );
		}

		if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
			IOFunctions.println( "Found peaks (possible beads): " + view.getBeadStructure().getBeadList().size() + " in view " + view.getName() );

		//
		// do we want to re-localize all detections with a gauss fit?
		//
		if ( conf.doFit == 3 )
		{
			if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
    			IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Starting Gaussian fit for all detections (this will take a little)");
			
			double sxy = 2;//10;
			double sz = 2;//(1.5 * sxy) / conf.zStretching;
			
			IJ.log( "Assumed sigma: [" + sxy + ", " + sxy + ", " + sz + "]" );
				
			final double[] typicalSigma = new double[]{ sxy, sxy, sz };
			
			gaussFit( view.getImage(), view.getBeadStructure().getBeadList(), typicalSigma );
		}
			
		// close the image if no re-localization is required and/or the memory is low
		if ( !( conf.doFit == 2 && conf.doGaussKeepImagesOpen ) )
			view.closeImage();
		
		//
		// Store segmentation in a file
		//
		if ( conf.writeSegmentation )
			IOFunctions.writeSegmentation( view, conf.registrationFiledirectory );										
	}
	
	if ( viewStructure.getDebugLevel() <= ViewStructure.DEBUG_MAIN )
	{
		int p1 = (int)Math.round( (double)benchmark.openFiles/((double)benchmark.computation+(double)benchmark.openFiles) * 100 );
		int p2 = (int)Math.round( (double)benchmark.computation/((double)benchmark.computation+(double)benchmark.openFiles) * 100 );
		IJ.log( "Opening files took: " + benchmark.openFiles/1000 + " sec (" + p1 + " %)" );
		IJ.log( "Computation took: " + benchmark.computation/1000 + " sec (" + p2 + " %)" );
	}
}