net.imglib2.img.display.imagej.ImageJFunctions Java Examples
The following examples show how to use
net.imglib2.img.display.imagej.ImageJFunctions.
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: FastFusionTools.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { final ImagePlus imp = IJ.openImage( "/Users/david/Desktop/stable HelaK-GFP-H2A.Z20000.tif" ); new ImageJ(); RandomAccessibleInterval< ? extends RealType > img = ImageJFunctions.wrapReal( imp ); ArrayImg< FloatType, FloatArray > f = ArrayImgs.floats( 1024, 1024 ); ArrayImg< FloatType, FloatArray > w = ArrayImgs.floats( 1024, 1024 ); RandomAccessibleInterval< FloatType > interp = (RandomAccessibleInterval< FloatType >) getLinearInterpolation( img, new FloatType(), new float[] {0.5f,0.5f}, Executors.newSingleThreadExecutor() ).getA(); RandomAccessibleInterval< FloatType > weight = new ArrayImgFactory( new FloatType() ).create( interp ); applyWeights( interp, weight, new float[] {0.5f,0.5f}, new float[] {0,0}, new float[] {20,20}, false, Executors.newSingleThreadExecutor() ); addTranslated( Views.iterable( interp ), f, new int[] {500, 700}, Executors.newSingleThreadExecutor() ); addTranslated( Views.iterable( interp ), f, new int[] {400, 500}, Executors.newSingleThreadExecutor() ); addTranslated( Views.iterable( weight ), w, new int[] {500, 700}, Executors.newSingleThreadExecutor() ); addTranslated( Views.iterable( weight ), w, new int[] {400, 500}, Executors.newSingleThreadExecutor() ); normalizeWeights( f, w, Executors.newSingleThreadExecutor() ); ImageJFunctions.show( f ); }
Example #2
Source File: GenerateSpimData.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static void main( String[] args ) { SpimData spimData = grid3x2(); SequenceDescription sd = spimData.getSequenceDescription(); ImgLoader i = sd.getImgLoader(); TimePoint firstTp = sd.getTimePoints().getTimePointsOrdered().get( 0 ); int tpId = firstTp.getId(); for ( final ViewSetup vs: spimData.getSequenceDescription().getViewSetups().values() ) { SetupImgLoader< ? > sil = i.getSetupImgLoader( vs.getId() ); ViewDescription vd = sd.getViewDescription( tpId, vs.getId() ); Tile t = vd.getViewSetup().getTile(); if ( t.hasLocation() ) System.out.println( "Loading: " + t.getName() + " " + Util.printCoordinates( t.getLocation() ) + " " + vd.getViewSetup().getChannel().getName() ); else System.out.println( "Loading: " + t.getName() + " (unknown location) " + vd.getViewSetup().getChannel().getName() ); ImageJFunctions.show( (RandomAccessibleInterval< UnsignedShortType >)sil.getImage( tpId, ImgLoaderHints.LOAD_COMPLETELY ) ).resetDisplayRange(); } }
Example #3
Source File: Downsample.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public static void main( String[] args ) { final Img< FloatType > img; //img = OpenImg.open( "/Users/preibischs/Documents/Microscopy/SPIM/HisYFP-SPIM/img_Angle0.tif", new ArrayImgFactory< FloatType >() ); img = new ArrayImgFactory< FloatType >().create( new long[]{ 515, 231, 15 }, new FloatType() ); final Cursor< FloatType > c = img.localizingCursor(); while ( c.hasNext() ) { c.next().set( c.getIntPosition( 0 ) % 10 + c.getIntPosition( 1 ) % 13 + c.getIntPosition( 2 ) % 3 ); } new ImageJ(); ImageJFunctions.show( img ); ImageJFunctions.show( simple2x( img, img.factory(), new boolean[]{ true, true, true } ) ); }
Example #4
Source File: BlendingRealRandomAccess.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static void main( String[] args ) { new ImageJ(); Img< FloatType > img = ArrayImgs.floats( 500, 500 ); BlendingRealRandomAccess blend = new BlendingRealRandomAccess( img, new float[]{ 100, 0 }, new float[]{ 12, 150 } ); Cursor< FloatType > c = img.localizingCursor(); while ( c.hasNext() ) { c.fwd(); blend.setPosition( c ); c.get().setReal( blend.get().getRealFloat() ); } ImageJFunctions.show( img ); }
Example #5
Source File: BlendingRealRandomAccess.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public static void main( String[] args ) { new ImageJ(); Img< FloatType > img = ArrayImgs.floats( 500, 500 ); BlendingRealRandomAccess blend = new BlendingRealRandomAccess( img, new float[]{ 100, 0 }, new float[]{ 12, 150 } ); Cursor< FloatType > c = img.localizingCursor(); while ( c.hasNext() ) { c.fwd(); blend.setPosition( c ); c.get().setReal( blend.get().getRealFloat() ); } ImageJFunctions.show( img ); }
Example #6
Source File: WeightNormalizer.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public static void main( String[] args ) { new ImageJ(); Img< FloatType > img = ArrayImgs.floats( 500, 500 ); BlendingRealRandomAccess blend = new BlendingRealRandomAccess( img, new float[]{ 100, 0 }, new float[]{ 12, 150 } ); Cursor< FloatType > c = img.localizingCursor(); while ( c.hasNext() ) { c.fwd(); blend.setPosition( c ); c.get().setReal( blend.get().getRealFloat() ); } ImageJFunctions.show( img ); }
Example #7
Source File: LinearIntensityMap.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
public static void main( final String[] args ) { new ImageJ(); final double[] coefficients = new double[]{ 0, 2, 4, 8, 1, 1, 1, 1, 1, 10, 5, 1, 1, 1, 1, 1, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150 }; final LinearIntensityMap< DoubleType > transform = new LinearIntensityMap< DoubleType >( ArrayImgs.doubles( coefficients, 4, 4, 2 ) ); //final ImagePlus imp = new ImagePlus( "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png" ); final ImagePlus imp1 = new ImagePlus( "http://fly.mpi-cbg.de/~saalfeld/Pictures/norway.jpg"); final ArrayImg< FloatType, FloatArray > image1 = ArrayImgs.floats( ( float[] )imp1.getProcessor().convertToFloatProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedByteType, ByteArray > image2 = ArrayImgs.unsignedBytes( ( byte[] )imp1.getProcessor().convertToByteProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedShortType, ShortArray > image3 = ArrayImgs.unsignedShorts( ( short[] )imp1.getProcessor().convertToShortProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< ARGBType, IntArray > image4 = ArrayImgs.argbs( ( int[] )imp1.getProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); ImageJFunctions.show( ArrayImgs.doubles( coefficients, 4, 4, 2 ) ); transform.run( image1 ); transform.run( image2 ); transform.run( image3 ); transform.run( image4 ); ImageJFunctions.show( image1 ); ImageJFunctions.show( image2 ); ImageJFunctions.show( image3 ); ImageJFunctions.show( image4 ); }
Example #8
Source File: VolumeTimeseriesDemo.java From sciview with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void run() { final RandomAccessibleInterval<UnsignedByteType> dataset = makeDataset(); // try { // ioService.save( // ImageJFunctions.wrap(dataset,"test"), // "/home/kharrington/Data/sciview/test_volumetimeseries.tif"); // } catch (IOException e) { // e.printStackTrace(); // } IJ.saveAsTiff( ImageJFunctions.wrap(dataset,"test"), "/home/kharrington/Data/sciview/test_volumetimeseries.tif"); //ImageJFunctions.wrap(dataset, "test"); BdvFunctions.show(dataset, "test"); Volume v = (Volume) sciView.addVolume( dataset, new float[] { 1, 1, 1, 1 } ); v.setPixelToWorldRatio(0.1f);// FIXME v.setName( "Volume Render Demo" ); v.setDirty(true); v.setNeedsUpdate(true); sciView.setActiveNode(v); sciView.centerOnNode( sciView.getActiveNode() ); }
Example #9
Source File: PDFWriter.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * Handles a histogram the following way: create snapshot, log data, reset the * display range, apply the Fire LUT and finally store it as an iText PDF image. * Afterwards the image is reset to its orignal state again */ @Override public void handleHistogram(Histogram2D<T> histogram, String name) { RandomAccessibleInterval<LongType> image = histogram.getPlotImage(); ImagePlus imp = ImageJFunctions.wrapFloat( image, name ); // make a snapshot to be able to reset after modifications imp.getProcessor().snapshot(); imp.getProcessor().log(); imp.updateAndDraw(); imp.getProcessor().resetMinAndMax(); IJ.run(imp,"Fire", null); Overlay overlay = new Overlay(); /* * check if we should draw a regression line for the current * histogram. */ if (histogram.getDrawingSettings().contains(Histogram2D.DrawingFlags.RegressionLine)) { AutoThresholdRegression<T> autoThreshold = this.container.getAutoThreshold(); if (histogram != null && autoThreshold != null) { drawLine(histogram, overlay, image.dimension(0), image.dimension(1), autoThreshold.getAutoThresholdSlope(), autoThreshold.getAutoThresholdIntercept()); overlay.setStrokeColor(java.awt.Color.WHITE); imp.setOverlay(overlay); } } addImageToList(imp, name); // reset the imp from the log scaling we applied earlier imp.getProcessor().reset(); }
Example #10
Source File: PDFWriter.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
@Override public void handleImage(RandomAccessibleInterval<T> image, String name) { ImagePlus imp = ImageJFunctions.wrapFloat( image, name ); // set the display range double max = ImageStatistics.getImageMax(image).getRealDouble(); imp.setDisplayRange(0.0, max); addImageToList(imp, name); }
Example #11
Source File: DisplayImage.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public static < T extends RealType< T > & NativeType< T > > ImagePlus getImagePlusInstance( final RandomAccessibleInterval< T > img, final boolean virtualDisplay, final String title, final double min, final double max ) { ImagePlus imp = null; if ( img instanceof ImagePlusImg ) try { imp = ((ImagePlusImg<T, ?>)img).getImagePlus(); } catch (ImgLibException e) {} if ( imp == null ) { if ( virtualDisplay ) imp = ImageJFunctions.wrap( img, title ); else imp = ImageJFunctions.wrap( img, title ).duplicate(); } imp.setTitle( title ); imp.setDimensions( 1, (int)img.dimension( 2 ), 1 ); imp.setDisplayRange( min, max ); return imp; }
Example #12
Source File: MinFilterThreshold.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public static void main( final String[] args ) { new ImageJ(); ImagePlus imp = new ImagePlus( "/Users/preibischs/workspace/TestLucyRichardson/src/resources/dros-1.tif" ); Img< FloatType > img = ImageJFunctions.convertFloat( imp ); ImageJFunctions.show( img.copy() ); ImageJFunctions.show( computeLazyMinFilter( img, 5 ) ); }
Example #13
Source File: Block.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public static void main( String[] args ) { // define the blocksize so that it is one single block final RandomAccessibleInterval< FloatType > block = ArrayImgs.floats( 384, 384 ); final long[] blockSize = new long[ block.numDimensions() ]; block.dimensions( blockSize ); final RandomAccessibleInterval< FloatType > image = ArrayImgs.floats( 1024, 1024 ); final long[] imgSize = new long[ image.numDimensions() ]; image.dimensions( imgSize ); // whatever the kernel size is (extra size/2 in general) final long[] kernelSize = new long[]{ 16, 32 }; final BlockGeneratorFixedSizePrecise blockGenerator = new BlockGeneratorFixedSizePrecise( blockSize ); final Block[] blocks = blockGenerator.divideIntoBlocks( imgSize, kernelSize ); int i = 0; for ( final Block b : blocks ) { // copy data from the image to the block (including extra space for outofbounds/real image data depending on kernel size) b.copyBlock( Views.extendMirrorDouble( image ), block ); // do something with the block (e.g. also multithreaded, cluster, ...) for ( final FloatType f : Views.iterable( block ) ) f.set( i ); ++i; // write the block back (use a temporary image if multithreaded or in general not all are copied first) b.pasteBlock( image, block ); } ImageJFunctions.show( image ); }
Example #14
Source File: Fusion.java From Stitching with GNU General Public License v2.0 | 5 votes |
public static void main( String[] args ) { new ImageJ(); // test blending ImgFactory< FloatType > f = new ArrayImgFactory< FloatType >(); Img< FloatType > img = f.create( new int[] { 400, 400 }, new FloatType() ); Cursor< FloatType > c = img.localizingCursor(); final int numDimensions = img.numDimensions(); final double[] tmp = new double[ numDimensions ]; // for blending final long[] dimensions = new long[ numDimensions ]; img.dimensions( dimensions ); final float percentScaling = 0.2f; final double[] border = new double[ numDimensions ]; while ( c.hasNext() ) { c.fwd(); for ( int d = 0; d < numDimensions; ++d ) tmp[ d ] = c.getFloatPosition( d ); c.get().set( (float)BlendingPixelFusion.computeWeight( tmp, dimensions, border, percentScaling ) ); } ImageJFunctions.show( img ); Log.debug( "done" ); }
Example #15
Source File: ImgLib2Util.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public static void main( String[] args ) { new ImageJ(); final Img< FloatType > img = openAs32Bit( new File( "src/main/resources/mri-stack.tif" ) ); //final Img< FloatType > img = openAs32Bit( new File( "src/main/resources/bridge.png" ) ); ImageJFunctions.show( img ); }
Example #16
Source File: Save3dTIFF.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public <T extends RealType<T> & NativeType<T>> boolean exportImage( final RandomAccessibleInterval<T> img, final BoundingBoxGUI bb, final TimePoint tp, final ViewSetup vs, final double min, final double max ) { // do nothing in case the image is null if ( img == null ) return false; // determine min and max final float[] minmax; if ( Double.isNaN( min ) || Double.isNaN( max ) ) minmax = FusionHelper.minMax( img ); else minmax = new float[]{ (float)min, (float)max }; ImagePlus imp = null; if ( img instanceof ImagePlusImg ) try { imp = ((ImagePlusImg<T, ?>)img).getImagePlus(); } catch (ImgLibException e) {} if ( imp == null ) imp = ImageJFunctions.wrap( img, getImgTitler().getImageTitle( tp, vs ) ).duplicate(); imp.setTitle( getImgTitler().getImageTitle( tp, vs ) ); if ( bb != null ) { imp.getCalibration().xOrigin = -(bb.min( 0 ) / bb.getDownSampling()); imp.getCalibration().yOrigin = -(bb.min( 1 ) / bb.getDownSampling()); imp.getCalibration().zOrigin = -(bb.min( 2 ) / bb.getDownSampling()); imp.getCalibration().pixelWidth = imp.getCalibration().pixelHeight = imp.getCalibration().pixelDepth = bb.getDownSampling(); } imp.setDimensions( 1, (int)img.dimension( 2 ), 1 ); imp.setDisplayRange( minmax[ 0 ], minmax[ 1 ] ); imp.updateAndDraw(); final String fileName; if ( !getImgTitler().getImageTitle( tp, vs ).endsWith( ".tif" ) ) fileName = new File( path, getImgTitler().getImageTitle( tp, vs ) + ".tif" ).getAbsolutePath(); else fileName = new File( path, getImgTitler().getImageTitle( tp, vs ) ).getAbsolutePath(); if ( compress ) { IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Saving file " + fileName + ".zip" ); return new FileSaver( imp ).saveAsZip( fileName ); } else { IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Saving file " + fileName ); return new FileSaver( imp ).saveAsTiffStack( fileName ); } }
Example #17
Source File: RigidWarp.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { RandomAccessibleInterval< FloatType > a = ImgLib2Util.openAs32Bit( new File( "73.tif.zip" ) ); RandomAccessibleInterval< FloatType > b = ImgLib2Util.openAs32Bit( new File( "74.tif.zip" ) ); long slice = 40; ImageJFunctions.show( a ); a = Views.zeroMin( Views.hyperSlice( a, 2, slice )); b = Views.zeroMin( Views.hyperSlice( b, 2, slice )); TranslationGet t1 = new Translation2D(); TranslationGet t2 = new Translation2D(460, 0); ArrayList< Pair< RealInterval, AffineGet > > views = new ArrayList<Pair<RealInterval, AffineGet>>(); views.add( new ValuePair< RealInterval, AffineGet >( a, t1 ) ); views.add( new ValuePair< RealInterval, AffineGet >( b, t2 ) ); RealInterval overlap = BoundingBoxMaximalGroupOverlap.getMinBoundingIntervalSingle( views ); final RealInterval transformed1 = TransformTools.applyTranslation( a, t1, new boolean[] {false, false} ); final RealInterval transformed2 = TransformTools.applyTranslation( b, t2, new boolean[] {false, false} ); // get overlap in images' coordinates final RealInterval localOverlap1 = TransformTools.getLocalOverlap( transformed1, overlap ); final RealInterval localOverlap2 = TransformTools.getLocalOverlap( transformed2, overlap ); // round to integer interval final Interval interval1 = TransformTools.getLocalRasterOverlap( localOverlap1 ); final Interval interval2 = TransformTools.getLocalRasterOverlap( localOverlap2 ); //final WarpFunction warp = new TranslationWarp(3); final WarpFunction warp = new RigidWarp(2); //final WarpFunction warp = new AffineWarp( 3 ); // rotate second image AffineTransform2D rot = new AffineTransform2D(); rot.rotate( 1.4 * Math.PI / 180 ); RandomAccessibleInterval< FloatType > rotated = Views.interval( RealViews.affine( Views.interpolate( Views.extendMirrorSingle( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ), rot.copy() ), interval2); // show input new ImageJ(); ImageJFunctions.show( Views.interval( a, interval1 ) ); ImageJFunctions.show( rotated ); // downsample input RandomAccessibleInterval< FloatType > simple2x1 = Downsample.simple2x( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), new boolean[] {false, false} ); RandomAccessibleInterval< FloatType > simple2x2 = Downsample.simple2x( Views.zeroMin( Views.interval( rotated, interval2 ) ), new ArrayImgFactory<>(), new boolean[] {false, false} ); // align //Align< FloatType > lk = new Align<>( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), warp ); Align< FloatType > lk = new Align<>( simple2x1, new ArrayImgFactory<>(), warp ); //System.out.println( Util.printCoordinates( lk.align( Views.zeroMin( Views.interval( b, interval2 ) ), 100, 0.01 ).getRowPackedCopy() ) ); //final AffineTransform transform = lk.align( Views.zeroMin( rotated ), 100, 0.01 ); final AffineTransform transform = lk.align( simple2x2, 100, 0.1 ); // transformation matrix System.out.println( Util.printCoordinates( transform.getRowPackedCopy() ) ); // correct input and show RandomAccessibleInterval< FloatType > backRotated = Views.interval( RealViews.affine( Views.interpolate( Views.extendMirrorSingle( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ), rot.copy().preConcatenate( transform ).copy() ), interval2); ImageJFunctions.show( backRotated ); // constructor needs column packed matrix, therefore the transpose Matrix mt = new Matrix( transform.getRowPackedCopy(), 3).transpose(); Matrix rigid = mt.getMatrix( 0, 1, 0, 1 ); // check whether result is rotation matrix (det == +-1, orthogonal) System.out.println( rigid.det() ); System.out.println( Util.printCoordinates( rigid.times( rigid.transpose() ).getRowPackedCopy() ) ); }
Example #18
Source File: SingleWindowDisplay.java From Colocalisation_Analysis with GNU General Public License v3.0 | 4 votes |
/** * Draws the passed ImageResult on the ImagePlus of this class. If the image * is part of a CompositeImageResult then contained lines will also be drawn */ protected void drawImage(RandomAccessibleInterval<? extends RealType<?>> img) { // get ImgLib image as ImageJ image imp = ImageJFunctions.wrapFloat((RandomAccessibleInterval<T>) img, "TODO"); imagePanel.updateImage(imp); // set the display range // check if a LUT should be applied if (listOfLUTs.containsKey(img)) { // select linked look up table IJ.run(imp, listOfLUTs.get(img), null); } imp.getProcessor().resetMinAndMax(); boolean overlayModified = false; Overlay overlay = new Overlay(); // if it is the 2d histogram, we want to show the regression line if (isHistogram(img)) { Histogram2D<T> histogram = mapOf2DHistograms.get(img); /* * check if we should draw a regression line for the current * histogram. */ if (histogram.getDrawingSettings().contains(Histogram2D.DrawingFlags.RegressionLine)) { AutoThresholdRegression<T> autoThreshold = dataContainer.getAutoThreshold(); if (histogram != null && autoThreshold != null) { if (img == histogram.getPlotImage()) { drawLine(overlay, img, autoThreshold.getAutoThresholdSlope(), autoThreshold.getAutoThresholdIntercept()); overlayModified = true; } } } } if (overlayModified) { overlay.setStrokeColor(java.awt.Color.WHITE); imp.setOverlay(overlay); } imagePanel.repaint(); }
Example #19
Source File: Align.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Img< FloatType > a = ImgLib2Util.openAs32Bit( new File( "73.tif.zip" ) ); Img< FloatType > b = ImgLib2Util.openAs32Bit( new File( "74.tif.zip" ) ); TranslationGet t1 = new Translation3D(); TranslationGet t2 = new Translation3D(460, 0, 0); ArrayList< Pair< RealInterval, AffineGet > > views = new ArrayList<Pair<RealInterval, AffineGet>>(); views.add( new ValuePair< RealInterval, AffineGet >( a, t1 ) ); views.add( new ValuePair< RealInterval, AffineGet >( b, t2 ) ); RealInterval overlap = BoundingBoxMaximalGroupOverlap.getMinBoundingIntervalSingle( views ); final RealInterval transformed1 = TransformTools.applyTranslation( a, t1, new boolean[] {false, false, false} ); final RealInterval transformed2 = TransformTools.applyTranslation( b, t2, new boolean[] {false, false, false} ); // get overlap in images' coordinates final RealInterval localOverlap1 = TransformTools.getLocalOverlap( transformed1, overlap ); final RealInterval localOverlap2 = TransformTools.getLocalOverlap( transformed2, overlap ); // round to integer interval final Interval interval1 = TransformTools.getLocalRasterOverlap( localOverlap1 ); final Interval interval2 = TransformTools.getLocalRasterOverlap( localOverlap2 ); //final WarpFunction warp = new TranslationWarp(3); final WarpFunction warp = new RigidWarp(3); //final WarpFunction warp = new AffineWarp( 3 ); // rotate second image AffineTransform3D rot = new AffineTransform3D(); rot.rotate( 2, 2 * Math.PI / 180 ); RandomAccessibleInterval< FloatType > rotated = Views.interval( RealViews.affine( Views.interpolate( Views.extendBorder( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ), rot.copy() ), interval2); // show input new ImageJ(); ImageJFunctions.show( Views.interval( a, interval1 ), "target" ); ImageJFunctions.show( rotated, "in"); // downsample input RandomAccessibleInterval< FloatType > simple2x1 = Downsample.simple2x( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), new boolean[] {true, true, false} ); RandomAccessibleInterval< FloatType > simple2x2 = Downsample.simple2x( Views.zeroMin( Views.interval( rotated, interval2 ) ), new ArrayImgFactory<>(), new boolean[] {true, true, false} ); // align //Align< FloatType > lk = new Align<>( Views.zeroMin( Views.interval( a, interval1 ) ), new ArrayImgFactory<>(), warp ); Align< FloatType > lk = new Align<>( simple2x1, new ArrayImgFactory<>(), warp ); //System.out.println( Util.printCoordinates( lk.align( Views.zeroMin( Views.interval( b, interval2 ) ), 100, 0.01 ).getRowPackedCopy() ) ); //final AffineTransform transform = lk.align( Views.zeroMin( rotated ), 100, 0.01 ); final AffineTransform transform = lk.align( simple2x2, 100, 0.01 ); final AffineTransform scale = new AffineTransform( 3 ); scale.set( 2, 0, 0 ); scale.set( 1, 1, 1 ); transform.preConcatenate( scale ); // transformation matrix System.out.println( Util.printCoordinates( transform.getRowPackedCopy() ) ); // correct input and show RandomAccessibleInterval< FloatType > backRotated = Views.interval( RealViews.affine( Views.interpolate( Views.extendBorder( Views.zeroMin( Views.interval( b, interval2 ) ) ), new NLinearInterpolatorFactory<>() ), rot.copy().preConcatenate( transform ).copy() ), interval2); ImageJFunctions.show( backRotated, "out" ); // constructor needs column packed matrix, therefore the transpose Matrix mt = new Matrix( transform.getRowPackedCopy(), 4).transpose(); Matrix rigid = mt.getMatrix( 0, 2, 0, 2 ); // check whether result is rotation matrix (det == +-1, orthogonal) System.out.println( rigid.det() ); System.out.println( Util.printCoordinates( rigid.times( rigid.transpose() ).getRowPackedCopy() ) ); }
Example #20
Source File: EasyDisplay.java From Colocalisation_Analysis with GNU General Public License v3.0 | 4 votes |
@Override public void handleHistogram(Histogram2D<T> histogram, String name) { ImagePlus imp = ImageJFunctions.wrapFloat( histogram.getPlotImage(), name ); double max = ImageStatistics.getImageMax( histogram.getPlotImage() ).getRealDouble(); showImage( imp, max ); }
Example #21
Source File: EasyDisplay.java From Colocalisation_Analysis with GNU General Public License v3.0 | 4 votes |
@Override public void handleImage(RandomAccessibleInterval<T> image, String name) { ImagePlus imp = ImageJFunctions.wrapFloat( image, name ); double max = ImageStatistics.getImageMax( image ).getRealDouble(); showImage( imp, max ); }
Example #22
Source File: PhaseCorrelation2.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { new ImageJ(); Img<FloatType> img1 = ImgLib2Util.openAs32Bit(new File("src/main/resources/img1singleplane.tif")); Img<FloatType> img2 = ImgLib2Util.openAs32Bit(new File("src/main/resources/img2singleplane.tif")); ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); RandomAccessibleInterval<FloatType> pcm = calculatePCM(img1, img2, new ArrayImgFactory<FloatType>(), new FloatType(), new ArrayImgFactory<ComplexFloatType>(), new ComplexFloatType(), service ); PhaseCorrelationPeak2 shiftPeak = getShift(pcm, img1, img2); RandomAccessibleInterval<FloatType> res = PhaseCorrelation2Util.dummyFuse(img1, img2, shiftPeak,service); ImageJFunctions.show(res); }
Example #23
Source File: DifferenceOfMean.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override protected boolean setInteractiveValues( final Channel channel ) { final ViewId view = getViewSelection( "Interactive Difference-of-Mean", "Please select view to use for channel " + channel.getName(), channel ); if ( view == null ) return false; final ViewDescription viewDescription = spimData.getSequenceDescription().getViewDescription( view.getTimePointId(), view.getViewSetupId() ); if ( !viewDescription.isPresent() ) { IOFunctions.println( "You defined the view you selected as not present at this timepoint." ); IOFunctions.println( "timepoint: " + viewDescription.getTimePoint().getName() + " angle: " + viewDescription.getViewSetup().getAngle().getName() + " channel: " + viewDescription.getViewSetup().getChannel().getName() + " illum: " + viewDescription.getViewSetup().getIllumination().getName() ); return false; } RandomAccessibleInterval< net.imglib2.type.numeric.real.FloatType > img = openAndDownsample( spimData, viewDescription, new AffineTransform3D() ); if ( img == null ) { IOFunctions.println( "View not found: " + viewDescription ); return false; } preSmooth( img ); final ImagePlus imp = ImageJFunctions.wrapFloat( img, "" ).duplicate(); img = null; imp.setDimensions( 1, imp.getStackSize(), 1 ); imp.setTitle( "tp: " + viewDescription.getTimePoint().getName() + " viewSetup: " + viewDescription.getViewSetupId() ); imp.show(); imp.setSlice( imp.getStackSize() / 2 ); final InteractiveIntegral ii = new InteractiveIntegral(); final int channelId = channel.getId(); ii.setInitialRadius( Math.round( defaultRadius1[ channelId ] ) ); ii.setThreshold( (float)defaultThreshold[ channelId ] ); ii.setLookForMinima( defaultFindMin[ channelId ] ); ii.setLookForMaxima( defaultFindMax[ channelId ] ); ii.setMinIntensityImage( minIntensity ); // if is Double.NaN will be ignored ii.setMaxIntensityImage( maxIntensity ); // if is Double.NaN will be ignored ii.run( null ); while ( !ii.isFinished() ) { try { Thread.sleep( 100 ); } catch (InterruptedException e) {} } imp.close(); if ( ii.wasCanceld() ) return false; this.radius1[ channelId ] = defaultRadius1[ channelId ] = ii.getRadius1(); this.radius2[ channelId ] = defaultRadius2[ channelId ] = ii.getRadius2(); this.threshold[ channelId ] = defaultThreshold[ channelId ] = ii.getThreshold(); this.findMin[ channelId ] = defaultFindMin[ channelId ] = ii.getLookForMinima(); this.findMax[ channelId ] = defaultFindMax[ channelId ] = ii.getLookForMaxima(); return true; }
Example #24
Source File: OverlayFusion.java From Stitching with GNU General Public License v2.0 | 4 votes |
public static < T extends RealType< T > & NativeType< T > > ImagePlus createReRegisteredSeries( final T targetType, final ImagePlus imp, final ArrayList<InvertibleBoundable> models, final int dimensionality ) { final int numImages = imp.getNFrames(); // the size of the new image final int[] size = new int[ dimensionality ]; // the offset relative to the output image which starts with its local coordinates (0,0,0) final double[] offset = new double[ dimensionality ]; final int[][] imgSizes = new int[ numImages ][ dimensionality ]; for ( int i = 0; i < numImages; ++i ) { imgSizes[ i ][ 0 ] = imp.getWidth(); imgSizes[ i ][ 1 ] = imp.getHeight(); if ( dimensionality == 3 ) imgSizes[ i ][ 2 ] = imp.getNSlices(); } // estimate the boundaries of the output image and the offset for fusion (negative coordinates after transform have to be shifted to 0,0,0) Fusion.estimateBounds( offset, size, imgSizes, models, dimensionality ); // for output final ImgFactory< T > f = new ImagePlusImgFactory< T >(); // the composite final ImageStack stack = new ImageStack( size[ 0 ], size[ 1 ] ); for ( int t = 1; t <= numImages; ++t ) { for ( int c = 1; c <= imp.getNChannels(); ++c ) { final Img<T> out = f.create( size, targetType ); final Img< FloatType > in = ImageJFunctions.convertFloat( Hyperstack_rearranger.getImageChunk( imp, c, t ) ); fuseChannel( out, Views.interpolate( Views.extendZero( in ), new NLinearInterpolatorFactory< FloatType >() ), offset, models.get( t - 1 ) ); try { final ImagePlus outImp = ((ImagePlusImg<?,?>)out).getImagePlus(); for ( int z = 1; z <= out.dimension( 2 ); ++z ) stack.addSlice( imp.getTitle(), outImp.getStack().getProcessor( z ) ); } catch (ImgLibException e) { Log.error( "Output image has no ImageJ type: " + e ); } } } //convertXYZCT ... ImagePlus result = new ImagePlus( "registered " + imp.getTitle(), stack ); // numchannels, z-slices, timepoints (but right now the order is still XYZCT) if ( dimensionality == 3 ) { result.setDimensions( size[ 2 ], imp.getNChannels(), imp.getNFrames() ); result = OverlayFusion.switchZCinXYCZT( result ); return CompositeImageFixer.makeComposite( result, CompositeImage.COMPOSITE ); } //Log.info( "ch: " + imp.getNChannels() ); //Log.info( "slices: " + imp.getNSlices() ); //Log.info( "frames: " + imp.getNFrames() ); result.setDimensions( imp.getNChannels(), 1, imp.getNFrames() ); if ( imp.getNChannels() > 1 ) return CompositeImageFixer.makeComposite( result, CompositeImage.COMPOSITE ); return result; }
Example #25
Source File: MinFilterThreshold.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public boolean run() { // fuse the dataset final ProcessFusion process; if ( loadSequentially ) process = new ProcessSequential( spimData, viewIdsToProcess, bb, false, false, 1 ); else process = new ProcessParalell( spimData, viewIdsToProcess, bb, false, false ); Img< FloatType > img = process.fuseStack( new FloatType(), new NearestNeighborInterpolatorFactory<FloatType>(), timepoint, channel ); final float[] minmax = FusionHelper.minMax( img ); final int effR = Math.max( radiusMin / bb.getDownSampling(), 1 ); final double threshold = (minmax[ 1 ] - minmax[ 0 ]) * ( background / 100.0 ) + minmax[ 0 ]; IOFunctions.println( "Fused image minimum: " + minmax[ 0 ] ); IOFunctions.println( "Fused image maximum: " + minmax[ 1 ] ); IOFunctions.println( "Threshold: " + threshold ); IOFunctions.println( "Computing minimum filter with effective radius of " + effR + " (downsampling=" + bb.getDownSampling() + ")" ); img = computeLazyMinFilter( img, effR ); if ( displaySegmentationImage ) ImageJFunctions.show( img ); this.min = new int[ img.numDimensions() ]; this.max = new int[ img.numDimensions() ]; if ( !computeBoundingBox( img, threshold, min, max ) ) return false; IOFunctions.println( "Bounding box dim scaled: [" + Util.printCoordinates( min ) + "] >> [" + Util.printCoordinates( max ) + "]" ); // adjust bounding box for downsampling and global coordinates for ( int d = 0; d < img.numDimensions(); ++d ) { // downsampling min[ d ] *= bb.getDownSampling(); max[ d ] *= bb.getDownSampling(); // global coordinates min[ d ] += bb.min( d ); max[ d ] += bb.min( d ); // effect of the min filter + extra space min[ d ] -= radiusMin * 3; max[ d ] += radiusMin * 3; } IOFunctions.println( "Bounding box dim global: [" + Util.printCoordinates( min ) + "] >> [" + Util.printCoordinates( max ) + "]" ); return true; }
Example #26
Source File: InteractiveProjections.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
protected ImagePlus showProjection( final Img< FloatType > img ) { final ImagePlus imp = ImageJFunctions.wrapFloat( img, "Max Projection" ); imp.show(); return imp; }
Example #27
Source File: DifferenceOfGaussian.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override protected boolean setInteractiveValues( final Channel channel ) { final ViewId view = getViewSelection( "Interactive Difference-of-Gaussian", "Please select view to use for channel " + channel.getName(), channel ); if ( view == null ) return false; final ViewDescription viewDescription = spimData.getSequenceDescription().getViewDescription( view.getTimePointId(), view.getViewSetupId() ); if ( !viewDescription.isPresent() ) { IOFunctions.println( "You defined the view you selected as not present at this timepoint." ); IOFunctions.println( "timepoint: " + viewDescription.getTimePoint().getName() + " angle: " + viewDescription.getViewSetup().getAngle().getName() + " channel: " + viewDescription.getViewSetup().getChannel().getName() + " illum: " + viewDescription.getViewSetup().getIllumination().getName() ); return false; } RandomAccessibleInterval< net.imglib2.type.numeric.real.FloatType > img = openAndDownsample( spimData, viewDescription, new AffineTransform3D() ); if ( img == null ) { IOFunctions.println( "View not found: " + viewDescription ); return false; } preSmooth( img ); final ImagePlus imp = ImageJFunctions.wrapFloat( img, "" ).duplicate(); img = null; imp.setDimensions( 1, imp.getStackSize(), 1 ); imp.setTitle( "tp: " + viewDescription.getTimePoint().getName() + " viewSetup: " + viewDescription.getViewSetupId() ); imp.show(); imp.setSlice( imp.getStackSize() / 2 ); imp.resetDisplayRange(); imp.setRoi( 0, 0, imp.getWidth()/3, imp.getHeight()/3 ); final InteractiveDoG idog = new InteractiveDoG( imp ); final int channelId = channel.getId(); idog.setSigma2isAdjustable( false ); idog.setInitialSigma( (float)defaultSigma[ channelId ] ); idog.setThreshold( (float)defaultThreshold[ channelId ] ); idog.setLookForMinima( defaultFindMin[ channelId ] ); idog.setLookForMaxima( defaultFindMax[ channelId ] ); idog.setMinIntensityImage( minIntensity ); // if is Double.NaN will be ignored idog.setMaxIntensityImage( maxIntensity ); // if is Double.NaN will be ignored idog.run( null ); while ( !idog.isFinished() ) { try { Thread.sleep( 100 ); } catch (InterruptedException e) {} } imp.close(); if ( idog.wasCanceled() ) return false; this.sigma[ channelId ] = defaultSigma[ channelId ] = idog.getInitialSigma(); this.threshold[ channelId ] = defaultThreshold[ channelId ] = idog.getThreshold(); this.findMin[ channelId ] = defaultFindMin[ channelId ] = idog.getLookForMinima(); this.findMax[ channelId ] = defaultFindMax[ channelId ] = idog.getLookForMaxima(); return true; }
Example #28
Source File: BlendedExtendedMirroredRandomAccesible2.java From BigStitcher with GNU General Public License v2.0 | 3 votes |
public static void main(String[] args) { new ImageJ(); Img<FloatType> img1 = ImgLib2Util.openAs32Bit(new File("src/main/resources/img1.tif")); long[] dims = new long[img1.numDimensions()]; BlendedExtendedMirroredRandomAccesible2<FloatType> ext = new BlendedExtendedMirroredRandomAccesible2<FloatType>(img1, new int[]{100, 100, 10}); ext.getExtInterval().dimensions(dims); Img<FloatType> img2 = ArrayImgs.floats(dims); // TODO: For efficiency reasons we should now also iterate the BlendedExtendedMirroredRandomAccesible and not the image long start = System.currentTimeMillis(); Cursor<FloatType> c = img2.cursor(); for (FloatType e : Views.iterable(Views.interval(ext, ext.getExtInterval()))) { c.fwd(); c.get().set(e); } long end = System.currentTimeMillis(); System.out.println(end-start); ImageJFunctions.show(img2); //RandomAccessibleInterval<FloatType> img3 = Views.interval(ext, ext.getExtInterval()); //ImageJFunctions.show(img3); }
Example #29
Source File: ContentBased.java From SPIM_Registration with GNU General Public License v2.0 | 3 votes |
public static void main( String[] args ) throws IncompatibleTypeException { new ImageJ(); ImagePlus imp = new ImagePlus( "/Users/preibischs/workspace/TestLucyRichardson/src/resources/dros-1.tif" ); Img< FloatType > img = ImageJFunctions.wrap( imp ); final double[] sigma1 = new double[]{ 20, 20 }; final double[] sigma2 = new double[]{ 30, 30 }; ContentBased< FloatType > cb = new ContentBased<FloatType>( img, img.factory().imgFactory( new ComplexFloatType() ), sigma1, sigma2 ); ImageJFunctions.show( cb.getContentBasedImg() ); }
Example #30
Source File: DisplayOverlapTestPopup.java From BigStitcher with GNU General Public License v2.0 | 2 votes |
@Override public void actionPerformed(ActionEvent e) { final SpimData spimData = (SpimData)panel.getSpimData(); List<List< ViewId >> views = ((GroupedRowWindow) panel).selectedRowsViewIdGroups(); BoundingBoxMaximalGroupOverlap< ViewId > bbDet = new BoundingBoxMaximalGroupOverlap<>( views, spimData ); BoundingBox bbOverlap = bbDet.estimate( "max overlap" ); System.out.println( "Overlap BB: " + Util.printInterval( bbOverlap ) ); GenericDialog gd = new GenericDialog( "Virtual Fusion" ); gd.addNumericField( "Downsampling", 1, 0 ); gd.showDialog(); if ( gd.wasCanceled() ) return; double downsampling = gd.getNextNumber(); //DisplayImage.getImagePlusInstance( new FusedRandomAccessibleInterval( new FinalInterval( dim ), images, weights ), true, "Fused, Virtual", 0, 255 ).show(); List<RandomAccessibleInterval< FloatType >> raiOverlaps = new ArrayList<>(); for (List< ViewId > tileViews : views) { List<List< ViewId >> wrapped = tileViews.stream().map( v -> { ArrayList< ViewId > wrp = new ArrayList<ViewId>(); wrp.add( v ); return wrp;} ).collect( Collectors.toList() ); List< RandomAccessibleInterval< FloatType > > openFused = openVirtuallyFused( spimData.getSequenceDescription(), spimData.getViewRegistrations(), wrapped, bbOverlap, new double[]{downsampling,downsampling,downsampling} ); GroupedViewAggregator gva = new GroupedViewAggregator(); gva.addAction( ActionType.AVERAGE, Channel.class, null ); gva.addAction( ActionType.PICK_BRIGHTEST, Illumination.class, null ); RandomAccessibleInterval< FloatType > raiI = gva.aggregate( openFused, views.stream().map( v -> v.iterator().next() ).collect( Collectors.toList() ), spimData.getSequenceDescription() ); raiOverlaps.add(raiI); } for (RandomAccessibleInterval< FloatType > rai : raiOverlaps) ImageJFunctions.show( rai ); RandomAccessibleInterval< FloatType > rai1 = raiOverlaps.get(0); RandomAccessibleInterval< FloatType > rai2 = raiOverlaps.get(1); //rai1 = ImageJFunctions.wrapFloat( ImageJFunctions.show( rai1 ).duplicate()); //rai2 = ImageJFunctions.wrapFloat( ImageJFunctions.show( rai2 ).duplicate()); ExecutorService service = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors() * 2 ); Pair< Translation, Double > shift = PairwiseStitching.getShift( rai1, rai2, new Translation( rai1.numDimensions() ), new Translation( rai1.numDimensions() ), PairwiseStitchingParameters.askUserForParameters(), service ); final double[] translation = shift.getA().getTranslationCopy(); System.out.println( Util.printCoordinates( translation ) ); System.out.println( shift.getB() ); for (int d = 0; d <translation.length; d++) translation[d] *= downsampling; System.out.println( spimData.getViewRegistrations().getViewRegistration( views.get( 1 ).get( 0 ) ).getModel().copy().concatenate( new Translation(translation) ) ); }