Digital Signal Processing Reference
In-Depth Information
12.1 RGB-Farbbilder
1 // File IDXtoRGB_.java
2
3 import ij.ImagePlus;
4 import ij.plugin.filter.PlugInFilter;
5 import ij.process.ColorProcessor;
6 import ij.process.ImageProcessor;
7 import java.awt.image.IndexColorModel;
8
9 public class IDXtoRGB_ implements PlugInFilter {
10
Programm 12.4
Konvertierung eines Indexbilds in ein
RGB-Vollfarbenbild (ImageJ-Plugin).
static final int R = 0, G = 1, B = 2;
11
12
public void run(ImageProcessor ip) {
int w = ip.getWidth();
13
int h = ip.getHeight();
14
15
16
//retrieve the lookup tables (maps) for R,G,B
IndexColorModel icm =
17
(IndexColorModel) ip.getColorModel();
18
int mapSize = icm.getMapSize();
19
byte[] Rmap = new byte[mapSize]; icm.getReds(Rmap);
20
byte[] Gmap = new byte[mapSize]; icm.getGreens(Gmap);
21
byte[] Bmap = new byte[mapSize]; icm.getBlues(Bmap);
22
23
24
//create new 24-bit RGB image
ColorProcessor cp = new ColorProcessor(w,h);
25
int[] RGB = new int[3];
26
for (int v = 0; v < h; v++) {
27
for (int u = 0; u < w; u++) {
28
int idx = ip.getPixel(u, v);
29
RGB[R] = Rmap[idx];
30
RGB[G] = Gmap[idx];
31
RGB[B] = Bmap[idx];
32
cp.putPixel(u, v, RGB);
33
}
34
}
35
ImagePlus cwin = new ImagePlus("RGB Image",cp);
36
cwin.show();
37
}
38
39
40
public int setup(String arg, ImagePlus imp) {
return DOES_8C + NO_CHANGES; //does not alter original image
41
}
42
43
44 }
Search WWH ::




Custom Search