Digital Signal Processing Reference
In-Depth Information
12 Farbbilder
1 // File IDXbrighten_.java
2
3 import ij.ImagePlus;
4 import ij.WindowManager;
5 import ij.plugin.filter.PlugInFilter;
6 import ij.process.ImageProcessor;
7 import java.awt.image.IndexColorModel;
8
9 public class IDXbrighten_ implements PlugInFilter {
10
11
Programm 12.3
Beispiel fur die Verarbeitung von In-
dexbildern (ImageJ-Plugin). Die Hel-
ligkeit des Bilds wird durch Verande-
rung der Farbtabelle um 10 Einhei-
ten erhoht. Das eigentliche Pixel-
Array (das die Indizes der Farbtabelle
enthalt) wird dabei nicht verandert.
public void run(ImageProcessor ip) {
IndexColorModel icm = (IndexColorModel) ip.getColorModel();
12
int pixBits = icm.getPixelSize();
13
int mapSize = icm.getMapSize();
14
15
16
//retrieve the current lookup tables (maps) for R,G,B
byte[] Rmap = new byte[mapSize]; icm.getReds(Rmap);
17
byte[] Gmap = new byte[mapSize]; icm.getGreens(Gmap);
18
byte[] Bmap = new byte[mapSize]; icm.getBlues(Bmap);
19
20
21
//modify the lookup tables
for (int idx = 0; idx < mapSize; idx++){
22
int r = 0xff & Rmap[idx]; //mask to treat as unsigned byte
23
int g = 0xff & Gmap[idx];
24
int b = 0xff & Bmap[idx];
25
Rmap[idx] = (byte) Math.min(r + 10, 255);
26
Gmap[idx] = (byte) Math.min(g + 10, 255);
27
Bmap[idx] = (byte) Math.min(b + 10, 255);
28
}
29
//create a new color model and apply to the image
30
IndexColorModel icm2 =
31
new IndexColorModel(pixBits, mapSize, Rmap, Gmap,Bmap);
32
ip.setColorModel(icm2);
33
//update the resulting image
34
WindowManager.getCurrentImage().updateAndDraw();
35
}
36
37
38
public int setup(String arg, ImagePlus imp) {
return DOES_8C; // this plugin works on indexed color images
39
}
40
41
42 }
des RGB-Farbraums (siehe Abschn. 12.5) und ist in der Regel aufwendi-
ger. In der Praxis verwendet man dafur naturlich meistens die fertigen
Konvertierungsmethoden in ImageJ (siehe S. 246).
Search WWH ::




Custom Search