Java Code Examples for mpicbg.imglib.image.Image#close()
The following examples show how to use
mpicbg.imglib.image.Image#close() .
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: LRFFTThreads.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
final protected static Thread getCPUThread1( final AtomicInteger ai, final Block[] blocks, final int[] blockSize, final ImageFactory< FloatType > factory, final Image<FloatType> image, final Image<FloatType> result, final FourierConvolution<FloatType, FloatType> fftConvolution1 ) { final Thread cpuThread1 = new Thread(new Runnable() { public void run() { final Image< FloatType > block = factory.createImage( blockSize ); int i; while ( ( i = ai.getAndIncrement() ) < blocks.length ) { convolve1BlockCPU( blocks[ i ], i, image, result, block, fftConvolution1 ); } block.close(); } }); return cpuThread1; }
Example 2
Source File: LRFFTThreads.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
final protected static Thread getCPUThread2( final AtomicInteger ai, final Block[] blocks, final int[] blockSize, final ImageFactory< FloatType > factory, final Image<FloatType> image, final Image<FloatType> result, final FourierConvolution<FloatType, FloatType> fftConvolution2 ) { final Thread cpuThread2 = new Thread(new Runnable() { public void run() { final Image< FloatType > block = factory.createImage( blockSize ); int i; while ( ( i = ai.getAndIncrement() ) < blocks.length ) { convolve2BlockCPU( blocks[ i ], image, result, block, fftConvolution2 ); } block.close(); } }); return cpuThread2; }
Example 3
Source File: LRFFTThreads.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
final protected static Thread getCUDAThread1( final AtomicInteger ai, final Block[] blocks, final int[] blockSize, final ImageFactory< FloatType > factory, final Image<FloatType> image, final Image<FloatType> result, final int deviceId, final Image<FloatType> kernel1 ) { final Thread cudaThread1 = new Thread(new Runnable() { public void run() { final Image< FloatType > block = factory.createImage( blockSize ); int i; while ( ( i = ai.getAndIncrement() ) < blocks.length ) { convolve1BlockCUDA( blocks[ i ], i, deviceId, image, result, block, kernel1, blockSize ); } block.close(); } }); return cudaThread1; }
Example 4
Source File: LRFFTThreads.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
final protected static Thread getCUDAThread2( final AtomicInteger ai, final Block[] blocks, final int[] blockSize, final ImageFactory< FloatType > factory, final Image<FloatType> image, final Image<FloatType> result, final int deviceId, final Image<FloatType> kernel2 ) { final Thread cudaThread2 = new Thread(new Runnable() { public void run() { final Image< FloatType > block = factory.createImage( blockSize ); int i; while ( ( i = ai.getAndIncrement() ) < blocks.length ) { convolve2BlockCUDA( blocks[ i ], deviceId, image, result, block, kernel2, blockSize ); } block.close(); } }); return cudaThread2; }
Example 5
Source File: DOM.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
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 6
Source File: PairWiseStitchingImgLib.java From Stitching with GNU General Public License v2.0 | 4 votes |
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 7
Source File: PairWiseStitchingImgLib.java From Stitching with GNU General Public License v2.0 | 4 votes |
/** * 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 8
Source File: DifferenceOfMean.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override public HashMap< ViewId, List< InterestPoint > > findInterestPoints( final TimePoint t ) { final HashMap< ViewId, List< InterestPoint > > interestPoints = new HashMap< ViewId, List< InterestPoint > >(); for ( final ViewDescription vd : SpimData2.getAllViewIdsForTimePointSorted( spimData, viewIdsToProcess, t ) ) { // make sure not everything crashes if one file is missing try { // // open the corresponding image (if present at this timepoint) // long time1 = System.currentTimeMillis(); if ( !vd.isPresent() ) continue; final Channel c = vd.getViewSetup().getChannel(); final AffineTransform3D correctCoordinates = new AffineTransform3D(); final RandomAccessibleInterval< net.imglib2.type.numeric.real.FloatType > input = openAndDownsample( spimData, vd, correctCoordinates ); long time2 = System.currentTimeMillis(); benchmark.openFiles += time2 - time1; preSmooth( input ); final Image< FloatType > img = ImgLib2.wrapFloatToImgLib1( (Img<net.imglib2.type.numeric.real.FloatType>)input ); // // compute Difference-of-Mean // List< InterestPoint > ips = ProcessDOM.compute( img, (Img<net.imglib2.type.numeric.real.FloatType>)input, radius1[ c.getId() ], radius2[ c.getId() ], (float)threshold[ c.getId() ], localization, imageSigmaX, imageSigmaY, imageSigmaZ, findMin[ c.getId() ], findMax[ c.getId() ], minIntensity, maxIntensity, limitDetections); img.close(); correctForDownsampling( ips, correctCoordinates ); if ( limitDetections ) ips = limitList( maxDetections, maxDetectionsTypeIndex, ips ); interestPoints.put( vd, ips ); benchmark.computation += System.currentTimeMillis() - time2; } catch ( Exception e ) { IOFunctions.println( "An error occured (DOM): " + e ); IOFunctions.println( "Failed to segment angleId: " + vd.getViewSetup().getAngle().getId() + " channelId: " + vd.getViewSetup().getChannel().getId() + " illumId: " + vd.getViewSetup().getIllumination().getId() + ". Continuing with next one." ); e.printStackTrace(); } } return interestPoints; }
Example 9
Source File: DifferenceOfGaussian.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override public HashMap< ViewId, List< InterestPoint > > findInterestPoints( final TimePoint t ) { final HashMap< ViewId, List< InterestPoint > > interestPoints = new HashMap< ViewId, List< InterestPoint > >(); for ( final ViewDescription vd : SpimData2.getAllViewIdsForTimePointSorted( spimData, viewIdsToProcess, t ) ) { // make sure not everything crashes if one file is missing try { // // open the corresponding image (if present at this timepoint) // long time1 = System.currentTimeMillis(); if ( !vd.isPresent() ) continue; final Channel c = vd.getViewSetup().getChannel(); final AffineTransform3D correctCoordinates = new AffineTransform3D(); final RandomAccessibleInterval< net.imglib2.type.numeric.real.FloatType > input = openAndDownsample( spimData, vd, correctCoordinates ); long time2 = System.currentTimeMillis(); benchmark.openFiles += time2 - time1; preSmooth( input ); final Image< FloatType > img = ImgLib2.wrapFloatToImgLib1( (Img<net.imglib2.type.numeric.real.FloatType>)input ); // // compute Difference-of-Gaussian // List< InterestPoint > ips = ProcessDOG.compute( cuda, deviceList, accurateCUDA, percentGPUMem, img, (Img<net.imglib2.type.numeric.real.FloatType>)input, (float)sigma[ c.getId() ], (float)threshold[ c.getId() ], localization, Math.min( imageSigmaX, (float)sigma[ c.getId() ] ), Math.min( imageSigmaY, (float)sigma[ c.getId() ] ), Math.min( imageSigmaZ, (float)sigma[ c.getId() ] ), findMin[ c.getId() ], findMax[ c.getId() ], minIntensity, maxIntensity, limitDetections ); img.close(); correctForDownsampling( ips, correctCoordinates ); if ( limitDetections ) ips = limitList( maxDetections, maxDetectionsTypeIndex, ips ); interestPoints.put( vd, ips ); benchmark.computation += System.currentTimeMillis() - time2; } catch ( Exception e ) { IOFunctions.println( "An error occured (DOG): " + e ); IOFunctions.println( "Failed to segment angleId: " + vd.getViewSetup().getAngle().getId() + " channelId: " + vd.getViewSetup().getChannel().getId() + " illumId: " + vd.getViewSetup().getIllumination().getId() + ". Continuing with next one." ); e.printStackTrace(); } } return interestPoints; }
Example 10
Source File: ProcessDOM.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * @param img - ImgLib1 image * @param imglib2img - ImgLib2 image (based on same image data as the ImgLib1 image, must be a wrap) * @param radius1 * @param radius2 * @param threshold * @param localization * @param imageSigmaX * @param imageSigmaY * @param imageSigmaZ * @param findMin * @param findMax * @param minIntensity * @param maxIntensity * @return */ public static ArrayList< InterestPoint > compute( final Image< FloatType > img, final Img< net.imglib2.type.numeric.real.FloatType > imglib2img, final int radius1, final int radius2, final float threshold, final int localization, final double imageSigmaX, final double imageSigmaY, final double imageSigmaZ, final boolean findMin, final boolean findMax, final double minIntensity, final double maxIntensity, final boolean keepIntensity ) { final Image< LongType > integralImg = IntegralImage3d.compute( img ); final float min, max; if ( Double.isNaN( minIntensity ) || Double.isNaN( maxIntensity ) || Double.isInfinite( minIntensity ) || Double.isInfinite( maxIntensity ) || minIntensity == maxIntensity ) { final float[] minmax = FusionHelper.minMax( imglib2img ); min = minmax[ 0 ]; max = minmax[ 1 ]; } else { min = (float)minIntensity; max = (float)maxIntensity; } IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): min intensity = " + min + ", max intensity = " + max ); // in-place final int sX1 = Math.max( 3, (int)Math.round( radius1 * (0.5/imageSigmaX ) ) * 2 + 1 ); final int sX2 = Math.max( 5, (int)Math.round( radius2 * (0.5/imageSigmaX ) ) * 2 + 1 ); final int sY1 = Math.max( 3, (int)Math.round( radius1 * (0.5/imageSigmaY ) ) * 2 + 1 ); final int sY2 = Math.max( 5, (int)Math.round( radius2 * (0.5/imageSigmaY ) ) * 2 + 1 ); final int sZ1 = Math.max( 3, (int)Math.round( radius1 * (0.5/imageSigmaZ ) ) * 2 + 1 ); final int sZ2 = Math.max( 5, (int)Math.round( radius2 * (0.5/imageSigmaZ ) ) * 2 + 1 ); IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Computing Difference-of-Mean, diameters = (" + sX1 + ", " + sX2 + ", " + sY1 + ", " + sY2 + ", " + sZ1 + ", " + sZ2 + ")" ); // in-place overwriting img if no adjacent Gauss fit is required final Image< FloatType > domImg; if ( localization == 2 ) { domImg = img.createNewImage(); } else { domImg = img; for ( final FloatType tt : img ) tt.setZero(); } DOM.computeDifferencOfMean3d( integralImg, domImg, sX1, sY1, sZ1, sX2, sY2, sZ2, min, max ); // close integral img integralImg.close(); IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Extracting peaks (radius=" + radius1 + ", threshold=" + threshold + ")"); // compute the maxima/minima final ArrayList< SimplePeak > peaks = InteractiveIntegral.findPeaks( domImg, threshold ); final ArrayList< InterestPoint > finalPeaks; if ( localization == 0 ) finalPeaks = Localization.noLocalization( peaks, findMin, findMax, keepIntensity ); else if ( localization == 1 ) finalPeaks = Localization.computeQuadraticLocalization( peaks, domImg, findMin, findMax, threshold, keepIntensity ); else finalPeaks = Localization.computeGaussLocalization( peaks, domImg, ( radius2 + radius1 )/2.0, findMin, findMax, threshold, keepIntensity ); IOFunctions.println("(" + new Date(System.currentTimeMillis()) + "): Found " + finalPeaks.size() + " peaks." ); return finalPeaks; }
Example 11
Source File: Bead_Registration.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * Can be called with values[ 3 ], i.e. [initialsigma, sigma2, threshold] or * values[ 2 ], i.e. [initialsigma, threshold] * * The results are stored in the same array. * If called with values[ 2 ], sigma2 changing will be disabled * * @param text - the text which is shown when asking for the file * @param values - the intial values and also contains the result */ public static void getInteractiveDoGParameters( final String text, final double values[] ) { final GenericDialogPlus gd = new GenericDialogPlus( text ); gd.addFileField( "", spimDataDirectory, 50 ); gd.showDialog(); if ( gd.wasCanceled() ) return; final String file = gd.getNextString(); IOFunctions.println( "Loading " + file ); final Image<FloatType> img = LOCI.openLOCIFloatType( file, new ArrayContainerFactory() ); if ( img == null ) { IOFunctions.println( "File not found: " + file ); return; } img.getDisplay().setMinMax(); final ImagePlus imp = ImageJFunctions.copyToImagePlus( img ); img.close(); imp.show(); imp.setSlice( imp.getStackSize() / 2 ); imp.setRoi( 0, 0, imp.getWidth()/3, imp.getHeight()/3 ); final InteractiveDoG idog = new InteractiveDoG(); if ( values.length == 2 ) { idog.setSigma2isAdjustable( false ); idog.setInitialSigma( (float)values[ 0 ] ); idog.setThreshold( (float)values[ 1 ] ); } else { idog.setInitialSigma( (float)values[ 0 ] ); idog.setThreshold( (float)values[ 2 ] ); } idog.run( null ); while ( !idog.isFinished() ) SimpleMultiThreading.threadWait( 100 ); imp.close(); if ( values.length == 2) { values[ 0 ] = idog.getInitialSigma(); values[ 1 ] = idog.getThreshold(); } else { values[ 0 ] = idog.getInitialSigma(); values[ 1 ] = idog.getSigma2(); values[ 2 ] = idog.getThreshold(); } }
Example 12
Source File: Bead_Registration.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * Can be called with values[ 3 ], i.e. [r1, r2, threshold] (r2 is only written as result) * * The results are stored in the same array. * * @param text - the text which is shown when asking for the file * @param values - the intial values and also contains the result */ public static void getInteractiveIntegralParameters( final String text, final double values[] ) { final GenericDialogPlus gd = new GenericDialogPlus( text ); gd.addFileField( "", spimDataDirectory, 50 ); gd.showDialog(); if ( gd.wasCanceled() ) return; final String file = gd.getNextString(); IOFunctions.println( "Loading " + file ); final Image<FloatType> img = LOCI.openLOCIFloatType( file, new ArrayContainerFactory() ); if ( img == null ) { IOFunctions.println( "File not found: " + file ); return; } img.getDisplay().setMinMax(); final ImagePlus imp = ImageJFunctions.copyToImagePlus( img ); img.close(); imp.show(); imp.setSlice( imp.getStackSize() / 2 ); final InteractiveIntegral ii = new InteractiveIntegral(); ii.setInitialRadius( Math.round( (float)values[ 0 ] ) ); ii.setThreshold( (float)values[ 2 ] ); ii.run( null ); while ( !ii.isFinished() ) SimpleMultiThreading.threadWait( 100 ); imp.close(); values[ 0 ] = ii.getRadius1(); values[ 1 ] = ii.getRadius2(); values[ 2 ] = ii.getThreshold(); }
Example 13
Source File: BayesMVDeconvolution.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
protected static Image< FloatType > loadInitialImage( final String fileName, final boolean checkNumbers, final float minValue, final int[] dimensions, final ImageFactory< FloatType > imageFactory ) { IOFunctions.println( "Loading image '" + fileName + "' as start for iteration." ); Image< FloatType > psi = LOCI.openLOCIFloatType( fileName, imageFactory ); if ( psi == null ) { IOFunctions.println( "Could not load image '" + fileName + "'." ); return null; } else { boolean dimensionsMatch = true; for ( int d = 0; d < psi.getNumDimensions(); ++d ) if ( psi.getDimension( d ) != dimensions[ d ] ) dimensionsMatch = false; if ( !dimensionsMatch ) { IOFunctions.println( "Dimensions of '" + fileName + "' do not match: " + Util.printCoordinates( psi.getDimensions() ) + " != " + Util.printCoordinates( dimensions ) ); psi.close(); return null; } if ( checkNumbers ) { IOFunctions.println( "Checking values of '" + fileName + "' you can disable this check by setting mpicbg.spim.postprocessing.deconvolution2.BayesMVDeconvolution.checkNumbers = false;" ); boolean smaller = false; boolean hasZerosOrNeg = false; for ( final FloatType v : psi ) { if ( v.get() < minValue ) smaller = true; if ( v.get() <= 0 ) { hasZerosOrNeg = true; v.set( minValue ); } } if ( smaller ) IOFunctions.println( "Some values '" + fileName + "' are smaller than the minimal value of " + minValue + ", this can lead to instabilities." ); if ( hasZerosOrNeg ) IOFunctions.println( "Some values '" + fileName + "' were smaller or equal to zero, they have been replaced with the min value of " + minValue ); } } return psi; }
Example 14
Source File: DOM.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
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 15
Source File: GaussContent.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
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 16
Source File: AverageContent.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
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; } }