Skip to content

Commit

Permalink
implemented workaround for ColorProcessor bug (pretty sure that's a b…
Browse files Browse the repository at this point in the history
…ug) ...
  • Loading branch information
StephanPreibisch committed Sep 25, 2024
1 parent 9294a2c commit 36cc1db
Showing 1 changed file with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import net.imglib2.img.Img;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory;
import net.imglib2.multithreading.SimpleMultiThreading;
import net.imglib2.realtransform.AffineTransform2D;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.view.Views;

Expand All @@ -32,6 +34,7 @@ public class SingleChannelMapper
final RealRandomAccess<UnsignedByteType> access;
final AffineTransform2D tInv;
final double[] tmp;
final boolean isRGB;

// 2x2 subsampling using top-left pixels
final int subsampling = 2;
Expand All @@ -44,7 +47,7 @@ public class SingleChannelMapper
// 3x3 subsampling using center pixels
//final int subsampling = 3;
//final long[] offset = new long[] { -1, -1 };

public SingleChannelMapper(final ImageProcessorWithMasks source,
final ImageProcessorWithMasks target,
final boolean isMappingInterpolated) {
Expand All @@ -53,18 +56,19 @@ public SingleChannelMapper(final ImageProcessorWithMasks source,
this.target = target;
this.isMappingInterpolated = isMappingInterpolated;

this.isRGB = ColorProcessor.class.isInstance( normalizedSource.ip );
if (isMappingInterpolated)
{
//this.normalizedSource.ip.setInterpolationMethod(ImageProcessor.BILINEAR);
final Img<UnsignedByteType> img = ImageJFunctions.wrapByte( new ImagePlus( "", normalizedSource.ip ) );
if ( img == null )
{
System.out.println( "normalizedSource.ip" + normalizedSource.ip );
if ( normalizedSource.ip != null )
System.out.println( "normalizedSource.ip class=" + normalizedSource.ip.getClass().getName() );
System.out.println( "img=" + img );
throw new RuntimeException( "Couldn't wrap normalizedSource.ip to imglib2 image." );
}

final Img<UnsignedByteType> img;

// TODO: this is a bug, this should not be a ColorProcessor
if ( isRGB )
img = ImageJFunctions.wrapByte( new ImagePlus( "", normalizedSource.ip.convertToByte( false ) ) );
else
img = ImageJFunctions.wrapByte( new ImagePlus( "", normalizedSource.ip ) );

final RealRandomAccessible<UnsignedByteType> rra = createSubsampled( img, subsampling, offset );
this.access = rra.realRandomAccess();

Expand All @@ -79,9 +83,6 @@ public SingleChannelMapper(final ImageProcessorWithMasks source,
t.translate( shift );

this.tInv = t.inverse();

//System.out.println( "t: " + t );
//System.out.println( "tInv: " + tInv );
}
else
{
Expand Down Expand Up @@ -162,7 +163,14 @@ public void mapInterpolated(final double sourceX,
tInv.apply( tmp, tmp );
access.setPosition( tmp );

target.ip.set(targetX, targetY, access.get().get() );

if ( isRGB )
{
final int value = access.get().get();
target.ip.set(targetX, targetY, ARGBType.rgba(value, value, value, 0) );
}
else
target.ip.set(targetX, targetY, access.get().get() );

//ImageJFunctions.show( img );
//SimpleMultiThreading.threadHaltUnClean();
Expand Down

0 comments on commit 36cc1db

Please sign in to comment.