Skip to content

Instantly share code, notes, and snippets.

@tinevez
Created January 29, 2019 14:47
Show Gist options
  • Save tinevez/e2a1af292d050bc217e4a05261f5904f to your computer and use it in GitHub Desktop.
Save tinevez/e2a1af292d050bc217e4a05261f5904f to your computer and use it in GitHub Desktop.
Demo for the binning op.
public class TestDriveBinningOp
{
@SuppressWarnings( "unchecked" )
public static < T extends RealType< T > > void main( final String[] args ) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, IOException
{
Locale.setDefault( Locale.ROOT );
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
final ImageJ ij = new ImageJ();
ij.launch( args );
final String imageFile = "samples/SingleSlice.tif";
final Object open = ij.io().open( imageFile );
ij.ui().show( open );
final int[] binFactors = new int[] { 4, 4 };
final Dataset dataset = ij.dataset().getDatasets().get( 0 );
@SuppressWarnings( "rawtypes" )
final BinningOp< T > binnerAvg = ( BinningOp ) Functions.unary(
ij.op(),
BinningOp.class,
Img.class,
RandomAccessibleInterval.class,
binFactors );
final Img< T > out = binnerAvg.calculate( ( RandomAccessibleInterval< T > ) dataset.getImgPlus() );
ij.ui().show( "Binned with mean", out );
@SuppressWarnings( "rawtypes" )
final BinningOp< T > binnerMax = ( BinningOp ) Functions.unary(
ij.op(),
BinningOp.class,
Img.class,
RandomAccessibleInterval.class,
binFactors,
Ops.Stats.Max.class );
final Img< T > out2 = binnerMax.calculate( ( RandomAccessibleInterval< T > ) dataset.getImgPlus() );
ij.ui().show( "Binned with max", out2 );
@SuppressWarnings( "rawtypes" )
final BinningOp< T > binnerMin = ( BinningOp ) Functions.unary(
ij.op(),
BinningOp.class,
Img.class,
RandomAccessibleInterval.class,
binFactors,
Ops.Stats.Min.class );
final Img< T > out3 = binnerMin.calculate( ( RandomAccessibleInterval< T > ) dataset.getImgPlus() );
ij.ui().show( "Binned with min", out3 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment