hanslovsky

Show

Jan 30th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.41 KB | None | 0 0
  1. package de.hanslovsky.watersheds.rewrite.sandbox;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import bdv.img.h5.H5Utils;
  7. import bdv.util.BdvFunctions;
  8. import bdv.util.BdvStackSource;
  9. import de.hanslovsky.watersheds.rewrite.util.IntensityMouseOver;
  10. import de.hanslovsky.watersheds.rewrite.util.Util;
  11. import gnu.trove.map.hash.TLongIntHashMap;
  12. import net.imglib2.RandomAccessibleInterval;
  13. import net.imglib2.converter.Converters;
  14. import net.imglib2.img.cell.CellImg;
  15. import net.imglib2.type.numeric.integer.LongType;
  16. import net.imglib2.type.numeric.real.FloatType;
  17. import net.imglib2.view.Views;
  18. import net.imglib2.view.composite.CompositeIntervalView;
  19. import net.imglib2.view.composite.RealComposite;
  20.  
  21. public class Show
  22. {
  23.  
  24.     public static void main( final String[] args )
  25.     {
  26.  
  27.         final String path = Util.HOME_DIR + "/local/tmp/excerpt-sliced-blocks.h5";
  28.         final int nIter = 8;
  29.  
  30.         final ArrayList< RandomAccessibleInterval< LongType > > labels = new ArrayList<>();
  31.         final ArrayList< RandomAccessibleInterval< LongType > > blocks = new ArrayList<>();
  32.  
  33.         for ( int i = 0; i < nIter; ++i )
  34.         {
  35.             labels.add( H5Utils.loadUnsignedLong( path, "labels-" + i, new int[] { 300, 300, 100 } ) );
  36.             blocks.add( H5Utils.loadUnsignedLong( path, "blocks-" + i, new int[] { 300, 300, 100 } ) );
  37.         }
  38.  
  39.         final TLongIntHashMap labelsCmap = new TLongIntHashMap();
  40.         final TLongIntHashMap blocksCmap = new TLongIntHashMap();
  41.  
  42.         {
  43.             final Random rng = new Random( 100 );
  44.             for ( final LongType l : Views.flatIterable( labels.get( 0 ) ) )
  45.                 if ( !labelsCmap.contains( l.get() ) )
  46.                     labelsCmap.put( l.get(), rng.nextInt() );
  47.         }
  48.  
  49.         {
  50.             final Random rng = new Random( 100 );
  51.             for ( final LongType b : Views.flatIterable( blocks.get( 0 ) ) )
  52.                 if ( !blocksCmap.contains( b.get() ) )
  53.                     blocksCmap.put( b.get(), rng.nextInt() );
  54.         }
  55.  
  56.         final BdvStackSource< LongType > labelsBdv = BdvFunctions.show( Views.stack( labels ), "labels", Util.bdvOptions( labels.get( 0 ) ) );
  57.         final BdvStackSource< LongType > blocksBdv = BdvFunctions.show( Views.stack( blocks ), "blocks", Util.bdvOptions( blocks.get( 0 ) ) );
  58.  
  59.         Util.replaceConverter( labelsBdv, 0, ( s, t ) -> {
  60.             t.set( labelsCmap.get( s.get() ) );
  61.         } );
  62.  
  63.         Util.replaceConverter( blocksBdv, 0, ( s, t ) -> {
  64.             t.set( blocksCmap.get( s.get() ) );
  65.         } );
  66.  
  67.         new IntensityMouseOver( labelsBdv.getBdvHandle().getViewerPanel() );
  68.         new IntensityMouseOver( blocksBdv.getBdvHandle().getViewerPanel() );
  69.  
  70.  
  71.         final int[] cellSize = new int[] { 50, 50, 50, 3 };
  72.         System.out.println( "Loading data" );
  73.         final CellImg< FloatType, ?, ? > data =
  74.                 H5Utils.loadFloat( path, "main", cellSize );
  75.         final int[] perm = Util.getFlipPermutation( data.numDimensions() - 1 );
  76.         final CompositeIntervalView< FloatType, RealComposite< FloatType > > affs =
  77.                 Views.collapseReal( Views.permuteCoordinates( data, perm, data.numDimensions() - 1 ) );
  78.  
  79.         final RandomAccessibleInterval< FloatType > maxAff = Converters.convert( affs, ( s, t ) -> {
  80.             Util.max( s, t, perm.length );
  81.             t.set( t.get() > 0.9f ? 1.0f : 0.0f );
  82.             t.mul( 1 << 16 );
  83.         }, new FloatType() );
  84.  
  85.         BdvFunctions.show( maxAff, "maxAff" );
  86.  
  87.  
  88. //      BdvFunctions.show( Views.stack( Collections.nCopies( nIter, maxAff ) ), "maxAff", BdvOptions.options().addTo( labelsBdv ) );
  89. //      BdvFunctions.show( Views.stack( Collections.nCopies( nIter, maxAff ) ), "maxAff", BdvOptions.options().addTo( blocksBdv ) );
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment