Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/subsampling' into subsampling
Browse files Browse the repository at this point in the history
# Conflicts:
#	render-app/src/main/java/org/janelia/alignment/mapper/SingleChannelMapper.java
  • Loading branch information
trautmane committed Sep 25, 2024
2 parents 2a0014e + 36cc1db commit 4104d31
Showing 1 changed file with 27 additions and 7 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,14 +34,19 @@ 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;
final long[] offset = new long[] { 0, 0 };

// 2x2 subsampling using bottom-right pixels
// final int subsampling = 2;
// final long[] offset = new long[] { -1, -1 };

// 3x3 subsampling using center pixels
final int subsampling = 3;
final long[] offset = new long[] { -1, -1 };
//final int subsampling = 3;
//final long[] offset = new long[] { -1, -1 };

public SingleChannelMapper(final ImageProcessorWithMasks source,
final ImageProcessorWithMasks target,
Expand All @@ -49,10 +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 ) );

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 @@ -67,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 @@ -150,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 4104d31

Please sign in to comment.