Skip to content

Commit

Permalink
correct code for 2x2 subsampling (bot right) @trautmane
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Sep 24, 2024
1 parent da2d8ec commit 9ac84e1
Showing 1 changed file with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.janelia.alignment.mapper;

import java.util.Arrays;

import ij.ImagePlus;
import ij.process.ByteProcessor;
import ij.process.ColorProcessor;
Expand All @@ -15,6 +17,7 @@
import net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory;
import net.imglib2.realtransform.AffineTransform2D;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.util.Util;
import net.imglib2.view.Views;

/**
Expand All @@ -27,14 +30,12 @@ public class SingleChannelMapper
protected final ImageProcessorWithMasks target;
protected final boolean isMappingInterpolated;

final Img<UnsignedByteType> img;
final RealRandomAccessible<UnsignedByteType> rra;
final RealRandomAccess<UnsignedByteType> access;
final AffineTransform2D t, tInv;
final AffineTransform2D tInv;
final double[] tmp;

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

public SingleChannelMapper(final ImageProcessorWithMasks source,
Expand All @@ -47,28 +48,31 @@ public SingleChannelMapper(final ImageProcessorWithMasks source,

if (isMappingInterpolated)
{
this.normalizedSource.ip.setInterpolationMethod(ImageProcessor.BILINEAR);
this.img = ImageJFunctions.wrapByte( new ImagePlus( "", normalizedSource.ip ) );
//this.rra = Views.interpolate( Views.extendZero( img ), new NLinearInterpolatorFactory<>() );
//this.access = rra.realRandomAccess();
//this.normalizedSource.ip.setInterpolationMethod(ImageProcessor.BILINEAR);
final Img<UnsignedByteType> img = ImageJFunctions.wrapByte( new ImagePlus( "", normalizedSource.ip ) );
final RealRandomAccessible<UnsignedByteType> rra = createSubsampled( img, subsampling, offset );
this.access = rra.realRandomAccess();

this.tmp = new double[ 2 ];

this.rra = createSubsampled( img, subsampling, offset );
this.access = rra.realRandomAccess();
// transform to undo the subsampling and shift
final AffineTransform2D t = new AffineTransform2D();
t.scale( subsampling );

final double[] shift = new double[ offset.length ];
Arrays.setAll( shift, d -> -offset[ d ]);
t.translate( shift );

// transform to undo the subsampling
this.t = new AffineTransform2D();
this.t.scale( subsampling );
this.tInv = t.inverse();

System.out.println( "t: " + t );
System.out.println( "tInv: " + tInv );
}
else
{
this.t = this.tInv = null;
this.img = null;
this.rra = null;
this.tInv = null;
this.access = null;
this.tmp = null;
//throw new RuntimeException( "not supported for subsampling" );
}
}

Expand Down

0 comments on commit 9ac84e1

Please sign in to comment.