Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Last active July 21, 2016 14:47
Show Gist options
  • Save bogovicj/cb69d9ea04df32005b9e8ad8005e2268 to your computer and use it in GitHub Desktop.
Save bogovicj/cb69d9ea04df32005b9e8ad8005e2268 to your computer and use it in GitHub Desktop.
Masking a RandomAccessibleInterval
public static <T extends RealType<T>, M extends RealType<M>> void maskToValue(
RandomAccessibleInterval<T> img,
RandomAccessibleInterval<M> mask,
RandomAccessibleInterval<T> out,
T val )
{
Cursor< M > maskC = Views.flatIterable( mask ).cursor();
RandomAccess< T > ira = img.randomAccess();
RandomAccess< T > ora = out.randomAccess();
while( maskC.hasNext() )
{
maskC.fwd();
ira.setPosition( maskC );
ora.setPosition( maskC );
if( maskC.get().getRealDouble() > 0 )
ora.get().set( ira.get() );
else
ora.get().set( val );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment