Skip to content

Commit

Permalink
Fix conversion in BlkAffineFusion
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Oct 1, 2024
1 parent bc05b8e commit 274750a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import net.imglib2.algorithm.blocks.transform.Transform;
import net.imglib2.algorithm.blocks.transform.Transform.Interpolation;
import net.imglib2.converter.Converter;
import net.imglib2.converter.RealUnsignedByteConverter;
import net.imglib2.converter.RealUnsignedShortConverter;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
Expand Down Expand Up @@ -172,11 +174,26 @@ private static < T extends NativeType< T > > BlockSupplier< T > convertToOutputT
{
return floatBlocks.andThen( Convert.convert( type, ClampType.CLAMP ) );
}
else if ( converter instanceof net.imglib2.display.LinearRange )
else if ( converter instanceof RealUnsignedByteConverter )
{
final net.imglib2.display.LinearRange range = ( net.imglib2.display.LinearRange ) converter;
final RealUnsignedByteConverter< ? > c = Cast.unchecked( converter );
final double min = c.getMin();
final double max = c.getMax();
final float scale = ( float ) ( 255.0 / ( max - min ) );
final float offset = ( float ) ( -min / ( max - min ) );
return floatBlocks
.andThen( LinearRange.linearRange( range.getMin(), range.getMax() ) )
.andThen( LinearRange.linearRange( scale, offset ) )
.andThen( Convert.convert( type, ClampType.CLAMP ) );
}
else if ( converter instanceof RealUnsignedShortConverter )
{
final RealUnsignedShortConverter< ? > c = Cast.unchecked( converter );
final double min = c.getMin();
final double max = c.getMax();
final float scale = ( float ) ( 65535.0 / ( max - min ) );
final float offset = ( float ) ( -min / ( max - min ) );
return floatBlocks
.andThen( LinearRange.linearRange( scale, offset ) )
.andThen( Convert.convert( type, ClampType.CLAMP ) );
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

class LinearRange
{
public static UnaryBlockOperator< FloatType, FloatType > linearRange( final double min, final double max )
public static UnaryBlockOperator< FloatType, FloatType > linearRange( final float scale, final float offset )
{
final float offset = ( float ) (-min / ( max - min ));
final float scale = ( float ) (1.0 / ( max - min ));
final FloatType type = new FloatType();
return new DefaultUnaryBlockOperator<>( type, type, 0, 0, new LinearRangeBlockProcessor( scale, offset ) );
}
Expand Down

0 comments on commit 274750a

Please sign in to comment.