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

- Addition of static methods to get the colors from a specified list of ColorTables

parent 58d126ca
No related branches found
No related tags found
1 merge request!40Draft: Resolve "Multi-channel image handling"
...@@ -2,23 +2,39 @@ package fr.pasteur.ida.zellige.steps; ...@@ -2,23 +2,39 @@ package fr.pasteur.ida.zellige.steps;
import net.imagej.Dataset; import net.imagej.Dataset;
import net.imagej.ImgPlus; import net.imagej.ImgPlus;
import net.imagej.display.DefaultDatasetView;
import net.imglib2.RandomAccess; import net.imglib2.RandomAccess;
import net.imglib2.display.ColorTable;
import net.imglib2.img.Img; import net.imglib2.img.Img;
import net.imglib2.type.NativeType; import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.RealType;
import java.util.ArrayList;
public class ChannelImageSelection< T extends RealType< T > & NativeType< T > > public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
{ {
private final static int GRAYS = 0;
private final static int RED = 1;
private final static int BLUE = 2;
private final static int GREEN = 3;
private final static int CYAN = 4;
private final static int MAGENTA = 5;
private final static int YELLOW = 6;
private final int targetChannel; private final int targetChannel;
private final Dataset dataset; private final Dataset dataset;
public static< T extends RealType< T > & NativeType< T > > Img< T > run(Dataset input, int targetChannel) public static < T extends RealType< T > & NativeType< T > > Img< T > run( Dataset input, int targetChannel )
{ {
ChannelImageSelection<T> channelImageSelection = new ChannelImageSelection<>( input, targetChannel ); ChannelImageSelection< T > channelImageSelection = new ChannelImageSelection<>( input, targetChannel );
return channelImageSelection.run(); return channelImageSelection.run();
} }
/**
*
* @param dataset
* @param targetChannel
*/
public ChannelImageSelection( Dataset dataset, int targetChannel ) public ChannelImageSelection( Dataset dataset, int targetChannel )
{ {
this.targetChannel = targetChannel; this.targetChannel = targetChannel;
...@@ -28,9 +44,9 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > > ...@@ -28,9 +44,9 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
public Img< T > run() public Img< T > run()
{ {
Img< T > input = ( ImgPlus< T > ) this.dataset.getImgPlus(); Img< T > input = ( ImgPlus< T > ) this.dataset.getImgPlus();
if (getTargetChannel() == 0) if ( getTargetChannel() == 0 )
{ {
return input; return input;
} }
else else
{ {
...@@ -43,7 +59,7 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > > ...@@ -43,7 +59,7 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
{ {
for ( int z = 0; z < ( int ) input.dimension( 3 ); z++ ) for ( int z = 0; z < ( int ) input.dimension( 3 ); z++ )
{ {
randomAccess.setPositionAndGet( x, y, getTargetChannel()-1, z ); randomAccess.setPositionAndGet( x, y, getTargetChannel() - 1, z );
randomAccess1.setPosition( new int[]{ x, y, z } ); randomAccess1.setPosition( new int[]{ x, y, z } );
randomAccess1.get().set( randomAccess.get() ); randomAccess1.get().set( randomAccess.get() );
} }
...@@ -52,8 +68,76 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > > ...@@ -52,8 +68,76 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
return output; return output;
} }
} }
public int getTargetChannel() public int getTargetChannel()
{ {
return targetChannel; return targetChannel;
} }
/**
*
* @param defaultDatasetView the input image
* @return an int array of colors
*/
private static int[] getColors( DefaultDatasetView defaultDatasetView )
{
return getColors( ( DefaultDatasetView ) defaultDatasetView.getColorTables() );
}
private static int [] getColors( ArrayList<ColorTable> colorTables)
{
int[] colors = new int[ colorTables.size() ];
if (colors.length == 1)
{
colors[0] = GRAYS;
return colors;
}
for ( int i = 0; i <colorTables.size(); i++ )
{
colors[i]= getColor( colorTables.get( i ));
}
return colors;
}
private static int getColor( ColorTable colorTable )
{
int R = colorTable.get( 0, 255 );
int G = colorTable.get( 1, 255 );
int B = colorTable.get( 2, 255 );
if ( R== 0)
{
if (G == 0)
{
return BLUE; // BLUE
}
else
{
if (B == 0)
{
return GREEN; // GREEN
}
return CYAN ; // CYAN
}
}
else
{
if (G == 0)
{
if (B == 0)
{
return RED; // RED
}
return MAGENTA ; // MAGENTA
}
else
{
if (B == 0)
{
return YELLOW; // YELLOW
}
return GRAYS ; // GRAYS
}
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment