File tree Expand file tree Collapse file tree 4 files changed +70
-5
lines changed
main/java/net/imglib2/imagej
test/java/net/imglib2/imagej Expand file tree Collapse file tree 4 files changed +70
-5
lines changed Original file line number Diff line number Diff line change
1
+ package net .imglib2 .imagej ;
2
+
3
+ import ij .process .LUT ;
4
+ import net .imglib2 .display .ColorTable ;
5
+ import net .imglib2 .util .Binning ;
6
+
7
+ /**
8
+ * Provides convenience functions to convert ImgLib2 {@link ColorTable}s into
9
+ * ImageJ {@link LUT} objects.
10
+ *
11
+ *
12
+ * @author Gabriel Selzer
13
+ */
14
+ public class ColorTableToLUT {
15
+
16
+ /**
17
+ * Copies the data from {@code table} into a new {@link LUT}
18
+ * @param table the {@link ColorTable} to convert
19
+ * @return a {@link LUT} containing the same color mapping as {@code table}
20
+ */
21
+ public static LUT convert (final ColorTable table ) {
22
+ byte [][] data = new byte [3 ][256 ];
23
+ for (int bin = 0 ; bin < 256 ; bin ++) {
24
+ data [ColorTable .RED ][bin ] = (byte ) table .get (ColorTable .RED , bin );
25
+ data [ColorTable .GREEN ][bin ] = (byte ) table .get (ColorTable .GREEN , bin );
26
+ data [ColorTable .BLUE ][bin ] = (byte ) table .get (ColorTable .BLUE , bin );
27
+ }
28
+ return new LUT (data [ColorTable .RED ], data [ColorTable .GREEN ], data [ColorTable .BLUE ]);
29
+ }
30
+ }
Original file line number Diff line number Diff line change 11
11
* {@link net.imglib2.display.ColorTable}s.
12
12
*
13
13
*
14
- * @author Stephan Preibisch
15
- * @author Stephan Saalfeld
16
- * @author Matthias Arzt
17
14
* @author Gabriel Selzer
18
15
*/
19
16
public class LUTToColorTable {
20
17
18
+ /**
19
+ * Wraps (i.e. copyless) {@code lut} into a {@link ColorTable}.
20
+ * @param lut the {@link LUT} to convert
21
+ * @return a {@link ColorTable} enclosing {@code lut}
22
+ */
21
23
public static ColorTable wrap (final LUT lut ) {
22
24
return new ColorTable () {
23
25
@ Override
Original file line number Diff line number Diff line change
1
+ package net .imglib2 .imagej ;
2
+
3
+ import ij .process .LUT ;
4
+ import net .imglib2 .display .ColorTable ;
5
+ import net .imglib2 .display .ColorTable8 ;
6
+ import org .junit .Test ;
7
+
8
+ import java .util .Random ;
9
+
10
+ import static org .junit .Assert .assertEquals ;
11
+
12
+ public class ColorTableToLUTTest {
13
+
14
+ @ Test
15
+ public void testConvertColorTable () {
16
+ Random r = new Random (0xdeadbeefL );
17
+ byte [] reds = new byte [256 ];
18
+ r .nextBytes (reds );
19
+ byte [] greens = new byte [256 ];
20
+ r .nextBytes (greens );
21
+ byte [] blues = new byte [256 ];
22
+ r .nextBytes (blues );
23
+ ColorTable table = new ColorTable8 (reds , greens , blues );
24
+ LUT actual = ColorTableToLUT .convert (table );
25
+ for (int i = 0 ; i < 256 ; i ++) {
26
+ // Note ColorTable.get unsigned bytes as ints
27
+ assertEquals (reds [i ], (byte ) actual .getRed (i ));
28
+ assertEquals (greens [i ], (byte ) actual .getGreen (i ));
29
+ assertEquals (blues [i ], (byte ) actual .getBlue (i ));
30
+ assertEquals ((byte ) 255 , (byte ) actual .getAlpha (i ));
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -20,10 +20,10 @@ public void testWrapLUT() {
20
20
Random r = new Random (0xdeadbeefL );
21
21
byte [] reds = new byte [256 ];
22
22
r .nextBytes (reds );
23
- byte [] blues = new byte [256 ];
24
- r .nextBytes (blues );
25
23
byte [] greens = new byte [256 ];
26
24
r .nextBytes (greens );
25
+ byte [] blues = new byte [256 ];
26
+ r .nextBytes (blues );
27
27
LUT lut = new LUT (reds , greens , blues );
28
28
ColorTable actual = LUTToColorTable .wrap (lut );
29
29
assertEquals (256 , actual .getLength ());
You can’t perform that action at this time.
0 commit comments