@Override public int map( final T type ) { return type.getInteger() - minVal; } }
@Override public T invMap(final int i) { T out = minType.createVariable(); out.setInteger(i + minVal); return out; }
/** * Given an IntegerType, returns a new Type containing its maximum possible * value. * @param <R> the IntegerType in question. * @param r a representative Type object. * @return a new Type containing its maximum possible * value. */ private static <R extends IntegerType<R>> R maxType(R r) { R type = r.createVariable(); type.setReal(r.getMaxValue()); return type; }
@Override public final void convert(final IntegerType<?> input, final IntegerType<?> output) { output.setInteger(input.getIntegerLong()); } };
/** * Given an IntegerType, returns a new Type containing its minimum possible * value. * @param <R> the IntegerType in question. * @param r a representative Type object. * @return a new Type containing its minimum possible * value. */ private static <R extends IntegerType<R>> R minType(R r) { R type = r.createVariable(); type.setReal(r.getMinValue()); return type; }
@Override public void set( final LabelingType< T > c ) { if ( c.mapping == mapping ) type.setInteger( c.type.getInteger() ); else type.setInteger( mapping.intern( c ).index ); generation.modCount++; }
@Override public void getCenterValue( final long binPos, final T value ) { long val; if ( tailBins ) { if ( binPos == 0 ) val = minVal - 1; // TODO HACK - what is best to return? else if ( binPos == bins - 1 ) val = maxVal + 1; // TODO same HACK else val = minVal + binPos - 1; } else { // no tail bins val = minVal + binPos; } value.setInteger( val ); }
public static < I extends IntegerType< I >> long[][] createElementFromImg( Img< I > kernel ) final int max = new Max< I, I >().compute( kernel.cursor(), kernel.firstElement().createVariable() ).getInteger(); final long[] origin = new long[ kernel.numDimensions() ]; boolean customOrigin = false; while ( c.hasNext() ) if ( c.next().getInteger() > 1 ) while ( c.hasNext() ) if ( c.next().getInteger() > 0 )
@Override public boolean conforms() { final Object inType = in().firstElement(); // HACK: Help the matcher overcome generics limitations. if (!(inType instanceof IntegerType)) return false; // HACK: Reject types that are small. // Because the InvertII is faster. // TODO: Think of a better solution. final T copy = in().firstElement().createVariable(); copy.setInteger(Long.MAX_VALUE); return copy.getIntegerLong() == Long.MAX_VALUE; }
/** * Create a labeling backed by a native image with custom strategy and image * factory * * @param strategyFactory * - the strategy factory that drives iteration and statistics * @param img */ public NativeImgLabeling( final LabelingROIStrategyFactory< T > strategyFactory, final Img< I > img ) { super( dimensions( img ), strategyFactory, new LabelingMapping< T >( img.firstElement().createVariable() ) ); this.img = img; this.generation = new long[ 1 ]; }
@Override public long map( final T value ) { final long val = value.getIntegerLong(); long pos; if ( val >= minVal && val <= maxVal ) { pos = val - minVal; if ( tailBins ) pos++; } else if ( tailBins ) { if ( val < minVal ) pos = 0; else pos = bins - 1; } else { // no tail bins and we are outside if ( val < minVal ) pos = Long.MIN_VALUE; else pos = Long.MAX_VALUE; } return pos; }
final RandomAccess< T > op0c = op0.randomAccess(); op0c.setPosition( op1 ); final T floodVal = op0c.get().copy(); final LinkedList< long[] > q = new LinkedList< long[] >(); q.addFirst( op1.clone() ); if ( rc.get().compareTo( floodVal ) == 0 ) if ( op0c.get().compareTo( floodVal ) == 0 ) rc.get().set( floodVal ); switch ( m_type )
private < T extends IntegerType< T > & NativeType< T > > void testIsRandomImageIntegerType( RandomAccessibleInterval< T > image ) { T type = Util.getTypeFromInterval( image ); double min = type.getMinValue(); double max = type.getMaxValue(); double actualMin = fold( Double.POSITIVE_INFINITY, Math::min, Views.iterable( image ) ); double actualMax = fold( Double.NEGATIVE_INFINITY, Math::max, Views.iterable( image ) ); // NB: Test, if the actual maximal value is close enough to the types getMaxValue(). String msg1 = "Actual max is to low, type: " + type.getClass().getSimpleName() + " max: " + max + " actual max: " + actualMax; assertTrue( msg1, min * 0.2 + max * 0.8 < actualMax ); // NB: Test, if the actual minimal value is close enough to the types getMinValue(). String msg2 = "Actual min is to high, type: " + type.getClass().getSimpleName() + " min: " + min + " actual min: " + actualMin; assertTrue( msg2, min * 0.8 + max * 0.2 > actualMin ); }
@Override public void compute(T in, T out) { BigInteger inverted = minMax.subtract(in.getBigInteger()); if( inverted.compareTo(minValue(out).getBigInteger()) <= 0) out.set(minValue(out)); else if(inverted.compareTo(maxValue(out).getBigInteger()) >= 0) out.set(maxValue(out)); else out.setBigInteger(inverted); } });
/** * Create a new {@link LabelingMapping} that maps label sets to the given * integral {@code indexType}. */ public LabelingMapping( final IntegerType< ? > indexType ) { this( ( int ) indexType.getMaxValue() ); }
@Override public MergeLabelings< L > copy() { return new MergeLabelings< L >( m_resType.copy(), m_adjustDimensionality ); }
for ( final T t : img ) final double v = t.getRealDouble(); bins[ ( int ) v ]++; for ( int i = 0; i < max; i++ ) val.setReal( i ); final long binPos = hist.map( val ); final long actual = hist.frequency( binPos );
private Img< T > createImage( final T type, final int max ) { final ImgFactory< T > imFactory = new ArrayImgFactory<>( type ); final Img< T > img = imFactory.create( DIMS ); // populate image with random samples for ( final T t : img ) t.setReal( max * Math.random() ); return img; }
@Override public boolean add( final T label ) { final int index = type.getInteger(); final int newindex = mapping.addLabelToSetAtIndex( label, index ).index; if ( newindex == index ) return false; type.setInteger( newindex ); generation.modCount++; return true; }
@Override public void getCenterValue( final long binPos, final T value ) { long val; if ( tailBins ) { if ( binPos == 0 ) val = minVal - 1; // TODO HACK - what is best to return? else if ( binPos == bins - 1 ) val = maxVal + 1; // TODO same HACK else val = minVal + binPos - 1; } else { // no tail bins val = minVal + binPos; } value.setInteger( val ); }