Skip to content
Snippets Groups Projects
Commit 58d126ca authored by Céline  TREBEAU's avatar Céline TREBEAU
Browse files

- Addition of new class to select the channel for the surface extraction

parent cf76cc00
No related branches found
No related tags found
1 merge request!40Draft: Resolve "Multi-channel image handling"
package fr.pasteur.ida.zellige.steps;
import net.imagej.Dataset;
import net.imagej.ImgPlus;
import net.imglib2.RandomAccess;
import net.imglib2.img.Img;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
{
private final int targetChannel;
private final Dataset dataset;
public static< T extends RealType< T > & NativeType< T > > Img< T > run(Dataset input, int targetChannel)
{
ChannelImageSelection<T> channelImageSelection = new ChannelImageSelection<>( input, targetChannel );
return channelImageSelection.run();
}
public ChannelImageSelection( Dataset dataset, int targetChannel )
{
this.targetChannel = targetChannel;
this.dataset = dataset;
}
public Img< T > run()
{
Img< T > input = ( ImgPlus< T > ) this.dataset.getImgPlus();
if (getTargetChannel() == 0)
{
return input;
}
else
{
Img< T > output = input.factory().create( input.dimension( 0 ), input.dimension( 1 ), input.dimension( 3 ) );
RandomAccess< T > randomAccess = input.randomAccess();
RandomAccess< T > randomAccess1 = output.randomAccess();
for ( int x = 0; x < ( int ) input.dimension( 0 ); x++ )
{
for ( int y = 0; y < ( int ) input.dimension( 1 ); y++ )
{
for ( int z = 0; z < ( int ) input.dimension( 3 ); z++ )
{
randomAccess.setPositionAndGet( x, y, getTargetChannel()-1, z );
randomAccess1.setPosition( new int[]{ x, y, z } );
randomAccess1.get().set( randomAccess.get() );
}
}
}
return output;
}
}
public int getTargetChannel()
{
return targetChannel;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment