Package net.imglib2.type.numeric.real

Examples of net.imglib2.type.numeric.real.FloatType


public final class RealFloatSamplerConverter< R extends RealType< R > > implements SamplerConverter< R, FloatType >
{
  @Override
  public FloatType convert( final Sampler< ? extends R > sampler )
  {
    return new FloatType( new RealConvertingFloatAccess< R >( sampler ) );
  }
View Full Code Here


  @Before
  public void setUp()
  {
    cellDimensions = new int[] { 8, 16, 5, 2 };
    dimensions = new long[] { 20, 37, 12, 33 };
    img = new CellImgFactory< FloatType >( cellDimensions ).create( dimensions, new FloatType() );
  }
View Full Code Here

  }

  @Test
  public void equalIterationOrder()
  {
    final Img< FloatType > img2 = new CellImgFactory< FloatType >( cellDimensions ).create( dimensions, new FloatType() );
    assertTrue( img2.iterationOrder().equals( img.iterationOrder() ) );
    assertTrue( img.iterationOrder().equals( img2.iterationOrder() ) );

    final Img< FloatType > img3 = new CellImgFactory< FloatType >( 9 ).create( dimensions, new FloatType() );
    assertFalse( img3.iterationOrder().equals( img.iterationOrder() ) );
    assertFalse( img.iterationOrder().equals( img3.iterationOrder() ) );

    final Img< FloatType > img4 = new ArrayImgFactory< FloatType >().create( dimensions, new FloatType() );
    assertFalse( img4.iterationOrder().equals( img.iterationOrder() ) );
    assertFalse( img.iterationOrder().equals( img4.iterationOrder() ) );
  }
View Full Code Here

  }

  public static boolean testImg( final long[] size, final ImgFactory< FloatType > factory1, final ImgFactory< FloatType > factory2 )
  {
    // create the image
    final Img< FloatType > img1 = factory1.create( size, new FloatType() );
    final Img< FloatType > img2 = factory2.create( size, new FloatType() );

    final int numDimensions = img1.numDimensions();

    // get a reference to compare to
    final float[] reference = createReference( img1 );

    // copy into a second image using simple cursors
    final Cursor< FloatType > cursor1 = img1.cursor();
    final Cursor< FloatType > cursor2 = img2.cursor();

    while ( cursor1.hasNext() )
    {
      cursor1.fwd();
      cursor2.fwd();

      cursor2.get().set( cursor1.get() );
    }

    cursor1.reset();
    cursor2.reset();

    // and copy right back
    while ( cursor2.hasNext() )
    {
      cursor1.fwd();
      cursor2.fwd();

      cursor1.get().set( cursor2.get() );
    }

    // copy back into a second image using localizable and positionable
    // cursors
    final Cursor< FloatType > localizableCursor1 = img1.localizingCursor();
    final RandomAccess< FloatType > positionable2 = img2.randomAccess();

    int i = 0;

    while ( localizableCursor1.hasNext() )
    {
      localizableCursor1.fwd();
      ++i;

      if ( i % 2 == 0 )
        positionable2.setPosition( localizableCursor1 );
      else
        positionable2.setPosition( localizableCursor1 );

      final FloatType t2 = positionable2.get();
      final FloatType t1 = localizableCursor1.get();
//      float f1 = t1.getRealFloat();
//      float f2 = t2.getRealFloat();
      t2.set( t1 );
//      positionable2.get().set( localizableCursor1.get() );
    }

    // copy again to the first image using a LocalizableByDimOutsideCursor
    // and a LocalizableByDimCursor
    final ExtendedRandomAccessibleInterval< FloatType, Img< FloatType > > extendedImg2 = new ExtendedRandomAccessibleInterval< FloatType, Img< FloatType > >( img2, new OutOfBoundsPeriodicFactory< FloatType, Img< FloatType > >() );
    final RandomAccess< FloatType > outsideCursor2 = extendedImg2.randomAccess();
    localizableCursor1.reset();

    final int[] pos = new int[ numDimensions ];
    i = 0;
    int direction = 1;

    try
    {
      while ( localizableCursor1.hasNext() )
      {
        localizableCursor1.fwd();
        localizableCursor1.localize( pos );
        ++i;

        // how many times far away from the original image do we grab
        // the pixel
        final int distance = i % 5;
        direction *= -1;

        pos[ i % numDimensions ] += img1.dimension( i % numDimensions ) * distance * direction;

        if ( i % 7 == 0 )
          outsideCursor2.setPosition( pos );
        else
          outsideCursor2.setPosition( pos );

        final FloatType t1 = localizableCursor1.get();
        final FloatType t2 = outsideCursor2.get();

//        final float f1 = t1.getRealFloat();
//        final float f2 = t2.getRealFloat();

        t1.set( t2 );
View Full Code Here

  @Test
  public void testFloatNoTails()
  {
    long binPos;
    final FloatType tmp = new FloatType();
    final Real1dBinMapper< FloatType > binMapper =
        new Real1dBinMapper< FloatType >( 0.0, 100.0, 100, false );
    assertEquals( 100, binMapper.getBinCount() );
    for ( double i = 0; i <= 100; i += 0.125 )
    {
      tmp.setReal( i );
      binPos = binMapper.map( tmp );
      double expectedBin = Math.floor( i );
      if ( i == 100.0 )
        expectedBin--;
      assertEquals( expectedBin, binPos, 0 );
      binMapper.getLowerBound( binPos, tmp );
      assertEquals( expectedBin, tmp.getRealDouble(), 0.0 );
      binMapper.getUpperBound( binPos, tmp );
      assertEquals( expectedBin + 1, tmp.getRealDouble(), 0.0 );
      binMapper.getCenterValue( binPos, tmp );
      assertEquals( expectedBin + 0.5, tmp.getRealDouble(), 0.0 );
    }
    tmp.setReal( -0.0001 );
    assertEquals( Long.MIN_VALUE, binMapper.map( tmp ) );
    tmp.setReal( 100.0001 );
    assertEquals( Long.MAX_VALUE, binMapper.map( tmp ) );
  }
View Full Code Here

  @Test
  public void testFloatTails()
  {
    long binPos;
    final FloatType tmp = new FloatType();
    final Real1dBinMapper< FloatType > binMapper =
        new Real1dBinMapper< FloatType >( 0.0, 100.0, 102, true );
    assertEquals( 102, binMapper.getBinCount() );
    for ( double i = 0; i <= 100; i += 0.125 )
    {
      tmp.setReal( i );
      binPos = binMapper.map( tmp );
      double expectedBin = Math.floor( i ) + 1;
      if ( i == 100.0 )
        expectedBin--;
      assertEquals( expectedBin, binPos, 0 );
      binMapper.getLowerBound( binPos, tmp );
      assertEquals( expectedBin - 1, tmp.getRealDouble(), 0.0 );
      binMapper.getUpperBound( binPos, tmp );
      assertEquals( expectedBin, tmp.getRealDouble(), 0.0 );
      binMapper.getCenterValue( binPos, tmp );
      assertEquals( expectedBin - 0.5, tmp.getRealDouble(), 0.0 );
    }
    tmp.setReal( -0.0001 );
    assertEquals( 0, binMapper.map( tmp ) );
    tmp.setReal( 100.0001 );
    assertEquals( 101, binMapper.map( tmp ) );
  }
View Full Code Here

  @Test
  public void testBinBoundariesTails()
  {
    long pos;
    final FloatType tmp = new FloatType();
    Real1dBinMapper< FloatType > binMapper;

    pos = 0;
    binMapper = new Real1dBinMapper< FloatType >( 0.0, 4.0, 4, true );
    binMapper.getLowerBound( pos, tmp );
    assertEquals( Double.NEGATIVE_INFINITY, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 0, tmp.getRealDouble(), 0 );
    assertFalse( binMapper.includesUpperBound( pos ) );

    pos = 1;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 0, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 2, tmp.getRealDouble(), 0 );
    assertFalse( binMapper.includesUpperBound( pos ) );

    pos = 2;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 2, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 4, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesUpperBound( pos ) );

    pos = 3;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 4, tmp.getRealDouble(), 0 );
    assertFalse( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( Double.POSITIVE_INFINITY, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesUpperBound( pos ) );

    tmp.setReal( -0.001 );
    pos = binMapper.map( tmp );
    assertEquals( 0, pos );

    tmp.setReal( 4.001 );
    pos = binMapper.map( tmp );
    assertEquals( 3, pos );
  }
View Full Code Here

  @Test
  public void testBinBoundariesNoTails()
  {
    long pos;
    final FloatType tmp = new FloatType();
    Real1dBinMapper< FloatType > binMapper;

    binMapper = new Real1dBinMapper< FloatType >( 0.0, 4.0, 4, false );
    pos = 0;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 0, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 1, tmp.getRealDouble(), 0 );
    assertFalse( binMapper.includesUpperBound( pos ) );

    pos = 1;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 1, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 2, tmp.getRealDouble(), 0 );
    assertFalse( binMapper.includesUpperBound( pos ) );

    pos = 2;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 2, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 3, tmp.getRealDouble(), 0 );
    assertFalse( binMapper.includesUpperBound( pos ) );

    pos = 3;
    binMapper.getLowerBound( pos, tmp );
    assertEquals( 3, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesLowerBound( pos ) );
    binMapper.getUpperBound( pos, tmp );
    assertEquals( 4, tmp.getRealDouble(), 0 );
    assertTrue( binMapper.includesUpperBound( pos ) );

    tmp.setReal( -0.001 );
    assertEquals( Long.MIN_VALUE, binMapper.map( tmp ) );

    tmp.setReal( 4.001 );
    assertEquals( Long.MAX_VALUE, binMapper.map( tmp ) );
  }
View Full Code Here

  @Test
  public void testEmptyMapper()
  {
    long pos;
    final FloatType tmp = new FloatType();
    Real1dBinMapper< FloatType > binMapper;

    binMapper = new Real1dBinMapper< FloatType >( 0.0, 0.0, 4, false );
    assertNotNull( binMapper );
    tmp.set( 0 );
    pos = binMapper.map( tmp );
    assertEquals( 0, pos );
  }
View Full Code Here

  /**
   * Generate a test image
   */
  protected Img< FloatType > makeTestImage3D( final long cubeLength )
  {
    return makeImage( new FloatType(), new TestGenerator( cubeLength ), new long[] { cubeLength, cubeLength, cubeLength } );
  }
View Full Code Here

TOP

Related Classes of net.imglib2.type.numeric.real.FloatType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.