diff --git a/src/main/java/fr/pasteur/ida/zellige/steps/ChannelImageSelection.java b/src/main/java/fr/pasteur/ida/zellige/steps/ChannelImageSelection.java
index 604ea6db8035629dc2bc29fcf2771f8b31f6a75f..6d3d53dbdbf0ccadd5e18749b0b9862cf6a309c0 100644
--- a/src/main/java/fr/pasteur/ida/zellige/steps/ChannelImageSelection.java
+++ b/src/main/java/fr/pasteur/ida/zellige/steps/ChannelImageSelection.java
@@ -2,23 +2,39 @@ package fr.pasteur.ida.zellige.steps;
import net.imagej.Dataset;
import net.imagej.ImgPlus;
+import net.imagej.display.DefaultDatasetView;
import net.imglib2.RandomAccess;
+import net.imglib2.display.ColorTable;
import net.imglib2.img.Img;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
+import java.util.ArrayList;
+
+
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 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();
}
+ /**
+ *
+ * @param dataset
+ * @param targetChannel
+ */
public ChannelImageSelection( Dataset dataset, int targetChannel )
{
this.targetChannel = targetChannel;
@@ -28,9 +44,9 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
public Img< T > run()
{
Img< T > input = ( ImgPlus< T > ) this.dataset.getImgPlus();
- if (getTargetChannel() == 0)
+ if ( getTargetChannel() == 0 )
{
- return input;
+ return input;
}
else
{
@@ -43,7 +59,7 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
{
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.get().set( randomAccess.get() );
}
@@ -52,8 +68,76 @@ public class ChannelImageSelection< T extends RealType< T > & NativeType< T > >
return output;
}
}
+
public int getTargetChannel()
{
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
+ }
+ }
+ }
}