diff --git a/render-app/src/main/java/org/janelia/alignment/mapper/SingleChannelMapper.java b/render-app/src/main/java/org/janelia/alignment/mapper/SingleChannelMapper.java index c092acb3d..6d431123d 100644 --- a/render-app/src/main/java/org/janelia/alignment/mapper/SingleChannelMapper.java +++ b/render-app/src/main/java/org/janelia/alignment/mapper/SingleChannelMapper.java @@ -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; @@ -32,6 +34,7 @@ public class SingleChannelMapper final RealRandomAccess access; final AffineTransform2D tInv; final double[] tmp; + final boolean isRGB; // 2x2 subsampling using top-left pixels final int subsampling = 2; @@ -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) { @@ -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 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 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 rra = createSubsampled( img, subsampling, offset ); this.access = rra.realRandomAccess(); @@ -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 { @@ -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();