Skip to content, Skip to search

Changes

ImgLib2 Examples

546 bytes added, 10:38, 2 December 2013
Updated example 6b to use ring kernel
<source lang="java">
/**
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * An exception is the 1D FFT implementation of Dave Hale which we use as a * library, which is released under the terms of the Common Public License - * v1.0, which is available at http://www.eclipse.org/legal/cpl-v10.html * * @author Stephan Preibisch (stephan.preibisch@gmx.de) */
import ij.ImageJ;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import net.imglib2.algorithm.fftfft2.FourierConvolutionFFTConvolution;
import net.imglib2.exception.IncompatibleTypeException;
import net.imglib2.img.Img;
/**
* Perform a gaussian convolution using fourier convolution */
public class Example6b
{
public Example6b() throws ImgIOException, IncompatibleTypeException { // open with ImgOpener using an ArrayImgFactory final Img< FloatType > image = new ImgOpener().openImg( "DrosophilaWing.tif", new FloatType() ); final Img< FloatType > kernel = new ImgOpener().openImg( "kernelGausskernelRing.tif", new FloatType() );
// normalize the kernel, otherwise we add energy to the image norm( kernel );
// display image & kernel ImageJFunctions.show( kernel ).setTitle( "kernel" ); ImageJFunctions.show( image ).setTitle( "drosophila wing");
// compute & show fourier convolution(in-place) new FFTConvolution<FloatType>( image, kernel ).run(); ImageJFunctions.show( FourierConvolution.convolve( image, kernel ) ) .setTitle( "convolution" ); }
/** * Computes the sum of all pixels in an iterable using RealSum * * @param iterable - the image data * @return - the sum of values */ public static < T extends RealType< T > > double sumImage( final Iterable< T > iterable ) { final RealSum sum = new RealSum();
for ( final T type : iterable ) sum.add( type.getRealDouble() );
return sum.getSum(); }
/** * Norms all image values so that their sum is 1 * * @param iterable - the image data */ public static void norm( final Iterable< FloatType > iterable ) { final double sum = sumImage( iterable );
for ( final FloatType type : iterable ) type.setReal( type.get() / sum ); }
public static void main( final String[] args ) throws ImgIOException, IncompatibleTypeException { // open an ImageJ window new ImageJ();
// run the example new Example6b(); }
}
 
</source>
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
735
edits