mpicbg.imglib.container.array.ArrayContainerFactory Java Examples
The following examples show how to use
mpicbg.imglib.container.array.ArrayContainerFactory.
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: LRFFT.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
final public static Image<FloatType> createImageFromArray( final float[] data, final int[] dim ) { final FloatAccess access = new FloatArray( data ); final Array<FloatType, FloatAccess> array = new Array<FloatType, FloatAccess>(new ArrayContainerFactory(), access, dim, 1 ); // create a Type that is linked to the container final FloatType linkedType = new FloatType( array ); // pass it to the DirectAccessContainer array.setLinkedType( linkedType ); return new Image<FloatType>(array, new FloatType()); }
Example #2
Source File: BinaryInterpolation2D.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
IDT2D(final Image<BitType> img) { this.w = img.getDimension(0); this.h = img.getDimension(1); ImageFactory<IntType> f = new ImageFactory<IntType>(new IntType(), new ArrayContainerFactory()); this.result = f.createImage(new int[]{w, h}); // Set all result pixels to infinity final int infinity = (w + h) * 9; for (final IntType v : this.result) { v.set(infinity); } // init result pixels with those of the image: this.csrc = img.createLocalizableByDimCursor(); this.cout = result.createLocalizableByDimCursor(); int count = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (isBoundary(x, y)) { setOutValueAt(x, y, 0); count++; } else if (isJustOutside(x, y)) { setOutValueAt(x, y, -1); } } } if (count > 0) { propagate(); } csrc.close(); cout.close(); }
Example #3
Source File: IntegralImageMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
private static final Image<UnsignedByteType> wrap(final byte[] p, final int[] dims) { final Array<UnsignedByteType,ByteArray> c = new Array<UnsignedByteType,ByteArray>( new ArrayContainerFactory(), new ByteArray(p), dims, 1); final UnsignedByteType t = new UnsignedByteType(c); c.setLinkedType(t); return new Image<UnsignedByteType>(c, t); }
Example #4
Source File: FileOpenMenuEntry.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override public void actionPerformed( final ActionEvent e ) { if ( chartPanel != null ) { // this might fail horribly, but at the moment it is the only solution // as right clicks in the chart are not reported to the mouse-listener // if they happen above the line drawings try { final JMenuItem item = (JMenuItem)e.getSource(); final JPopupMenu m = (JPopupMenu)item.getParent(); // location of the top left pixel of the chartpanel in screen coordinates final Point p = chartPanel.getLocationOnScreen(); // we parse the position of the JPopupMenu on the screen (AAARGH!!!) final String output = m.toString(); final String x = output.substring( output.indexOf( "desiredLocationX" ) ); final String y = output.substring( output.indexOf( "desiredLocationY" ) ); System.out.println( "chart: " +p ); System.out.println( "popup: " + x + ", " + y ); // and from that we get the relative coordinate in the chartpanel p.x = Integer.parseInt( x.substring( x.indexOf( "=" )+1, x.indexOf( "," ) ) ) - p.x; p.y = Integer.parseInt( y.substring( y.indexOf( "=" )+1, y.indexOf( "," ) ) ) - p.y; // now we transform it into the correct timelapse scale final int tp = MouseListenerTimelapse.getChartXLocation( p, chartPanel ); // now find the correct image for ( final RegistrationStatistics stat : data ) if ( stat.timePoint == tp ) { final Image<FloatType> image = LOCI.openLOCIFloatType( stat.worstView.getAbsolutePath(), new ArrayContainerFactory() ); ImageJFunctions.show( image ); break; } } catch ( Exception ex ) {} } }
Example #5
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 #6
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 #7
Source File: Block.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public static void main( String[] args ) { new ImageJ(); //final Image< FloatType > img = LOCI.openLOCIFloatType( "/Users/preibischs/Desktop/Geburtstagsfaust.jpg", new ArrayContainerFactory() ); final Image< FloatType > img = LOCI.openLOCIFloatType( "/Users/preibischs/Desktop/spim.tif", new ArrayContainerFactory() ); final Image< FloatType > kernel = FourierConvolution.createGaussianKernel( img.getContainerFactory(), new double[]{ 10, 10, 10 } ); //ImageJFunctions.show( img ); //final FourierConvolution< FloatType, FloatType > t = new FourierConvolution<FloatType, FloatType>( img, kernel ); //t.process(); //ImageJFunctions.show( t.getResult() ); final int[] imgSize = img.getDimensions();//new int[]{ 256, 384 }; final int[] blockSize = new int[]{ 256, 256, 256 }; //for ( int d = 0; d < blockSize.length; ++d ) // blockSize[ d ] = img.getDimension( d ) + kernel.getDimension( d ) - 1; final int[] kernelSize = kernel.getDimensions();//new int[]{ 51, 25 }; final Block[] blocks = Block.divideIntoBlocks( imgSize, blockSize, kernelSize ); final ArrayList< Image< FloatType > > blockImgs = new ArrayList< Image< FloatType > >(); final ImageFactory< FloatType > factory = new ImageFactory< FloatType >( new FloatType(), new ArrayContainerFactory() ); ImageJFunctions.show( img ); for ( int i = 0; i < blocks.length; ++i ) blockImgs.add( factory.createImage( blockSize ) ); long time = 0; //while ( time >= 0 ) { time = System.currentTimeMillis(); for ( int i = 0; i < blocks.length; ++i ) { blocks[ i ].copyBlock( img, blockImgs.get( i ) ); //ImageJFunctions.show( block ); } System.out.println( System.currentTimeMillis() - time ); //System.exit( 0 ); } /* final FourierConvolution< FloatType, FloatType > t2 = new FourierConvolution<FloatType, FloatType>( blockImgs.get( 0 ), kernel ); //t2.setExtendImageByKernelSize( false ); //for ( final FloatType t : block ) // t.set( t.get() + 20*(i+1) ); */ final Image< FloatType > img2 = img.createNewImage(); //while ( time > 0 ) { time = System.currentTimeMillis(); for ( int i = 0; i < blocks.length; ++i ) { //t2.replaceImage( blockImgs.get( i ) ); //t2.process(); blocks[ i ].pasteBlock( img2, blockImgs.get( i ) ); //ImageJFunctions.show( t.getResult() ); } System.out.println( System.currentTimeMillis() - time ); } ImageJFunctions.show( img2 ); }
Example #8
Source File: LRFFT.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public LRFFT( final Image<FloatType> image, final Image<FloatType> weight, final Image<FloatType> kernel, final int[] deviceList, final boolean useBlocks, final int[] blockSize ) { this.image = image; this.kernel1 = kernel; this.weight = weight; this.deviceList = deviceList; this.device0 = deviceList[ 0 ]; this.numDevices = deviceList.length; // figure out if we need GPU and/or CPU boolean anyGPU = false; boolean anyCPU = false; for ( final int i : deviceList ) { if ( i >= 0 ) anyGPU = true; else if ( i == -1 ) anyCPU = true; } this.useCUDA = anyGPU; this.useCPU = anyCPU; if ( useBlocks ) { this.useBlocks = true; // define the blocksize so that it is one single block this.blockSize = new int[ image.getNumDimensions() ]; for ( int d = 0; d < this.blockSize.length; ++d ) this.blockSize[ d ] = blockSize[ d ]; this.blocks = Block.divideIntoBlocks( image.getDimensions(), this.blockSize, kernel.getDimensions() ); // blocksize might change during division if they were too small //this.blockSize = blockSize.clone(); IOFunctions.println( "Number of blocks: " + this.blocks.length ); this.factory = new ImageFactory< FloatType >( new FloatType(), new ArrayContainerFactory() ); } else if ( this.useCUDA ) // and no blocks, i.e. one big block { this.useBlocks = true; // define the blocksize so that it is one single block this.blockSize = new int[ image.getNumDimensions() ]; for ( int d = 0; d < this.blockSize.length; ++d ) this.blockSize[ d ] = image.getDimension( d ) + kernel.getDimension( d ) - 1; this.blocks = Block.divideIntoBlocks( image.getDimensions(), this.blockSize, kernel.getDimensions() ); this.factory = new ImageFactory< FloatType >( new FloatType(), new ArrayContainerFactory() ); } else { this.blocks = null; this.blockSize = null; this.factory = null; this.useBlocks = false; } }
Example #9
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 #10
Source File: InteractiveDoG.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * Extract the current 2d region of interest from the souce image * * @param source - the source image, a {@link Image} which is a copy of the {@link ImagePlus} * @param rectangle - the area of interest * @param extraSize - the extra size around so that detections at the border of the roi are not messed up * @return */ protected Image<FloatType> extractImage( final FloatImagePlus< net.imglib2.type.numeric.real.FloatType > source, final Rectangle rectangle, final int extraSize ) { final Image<FloatType> img = new ImageFactory<FloatType>( new FloatType(), new ArrayContainerFactory() ).createImage( new int[]{ rectangle.width+extraSize, rectangle.height+extraSize } ); final int offsetX = rectangle.x - extraSize/2; final int offsetY = rectangle.y - extraSize/2; final int[] location = new int[ source.numDimensions() ]; if ( location.length > 2 ) location[ 2 ] = (imp.getCurrentSlice()-1)/imp.getNChannels(); final LocalizableCursor<FloatType> cursor = img.createLocalizableCursor(); final RandomAccess<net.imglib2.type.numeric.real.FloatType> positionable; if ( offsetX >= 0 && offsetY >= 0 && offsetX + img.getDimension( 0 ) < source.dimension( 0 ) && offsetY + img.getDimension( 1 ) < source.dimension( 1 ) ) { // it is completely inside so we need no outofbounds for copying positionable = source.randomAccess(); } else { positionable = Views.extendMirrorSingle( source ).randomAccess(); } while ( cursor.hasNext() ) { cursor.fwd(); cursor.getPosition( location ); location[ 0 ] += offsetX; location[ 1 ] += offsetY; positionable.setPosition( location ); cursor.getType().set( positionable.get().get() ); } return img; }
Example #11
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 #12
Source File: DOM.java From SPIM_Registration with GNU General Public License v2.0 | 2 votes |
public static void main( String args[] ) { new ImageJ(); //Image< FloatType > img1 = new ImageFactory<FloatType>( new FloatType(), new ArrayContainerFactory() ).createImage( new int[]{ 13, 13, 13 } ); //meanMirror( null, img1, 7, 7, 7, 0, 0 ); //ImageJFunctions.show( img1 ); //SimpleMultiThreading.threadHaltUnClean(); Image< FloatType > img = LOCI.openLOCIFloatType( "/Users/preibischs/Documents/Microscopy/SPIM/HisYFP-SPIM/spim_TL18_Angle0.tif", new ArrayContainerFactory() ); long ti = System.currentTimeMillis(); Image<FloatType> cb = computeContentBasedWeighting( img, 20, 40, 2.73f ); System.out.println( "Content-based took: " + (System.currentTimeMillis() - ti) + " ms." ); ImageJFunctions.show( cb ); SimpleMultiThreading.threadHaltUnClean(); 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(); meanMirror( integralImg, img, 31, 31, 11 ); ImageJFunctions.show( img ); SimpleMultiThreading.threadHaltUnClean(); final FloatType min = new FloatType(); final FloatType max = new FloatType(); DOM.computeMinMax( img, min, max ); final Image< FloatType > domImg = img.createNewImage(); long t = 0; int num = 10; for ( int i = 0; i < num; ++i ) { long t1 = System.currentTimeMillis(); DOM.computeDifferencOfMean3d( integralImg, domImg, 3, 3, 3, 5, 5, 5, min.get(), max.get() ); long t2 = System.currentTimeMillis(); t += (t2 - t1); System.out.println( "run " + i + ": " + (t2-t1) + " ms." ); } System.out.println( "avg: " + (t/num) + " ms." ); //DOM.computeDifferencOfMean( integralImg, img, 3, 3, 3, 5, 5, 5, min.get(), max.get() ); }