Digital Signal Processing Reference
In-Depth Information
12 Farbbilder
1 // File DesaturateContRGB_.java
2
3 import ij.ImagePlus;
4 import ij.plugin.filter.PlugInFilter;
5 import ij.process.ImageProcessor;
6
7 public class DesaturateContRGB_ implements PlugInFilter {
8
Programm 12.5
Kontinuierliche Desaturierung von
RGB-Farbbildern (ImageJ-Plugin).
Die verbleibende Farbigkeit wird
durch die Variable s in Zeile 8 ge-
steuert (entspr. s col in Gl. 12.9).
double s = 0.3; // color saturation value
9
10
public void run(ImageProcessor ip) {
//iterate over all pixels
11
for (int v = 0; v < ip.getHeight(); v++) {
12
for (int u = 0; u < ip.getWidth(); u++) {
13
14
15
//get int-packed color pixel
int c = ip.getPixel(u, v);
16
17
18
//extract RGB components from color pixel
int r = (c & 0xff0000) >> 16;
19
int g = (c & 0x00ff00) >> 8;
20
int b = (c & 0x0000ff);
21
22
23
//compute equiv. gray value
double y = 0.299 * r + 0.587 * g + 0.114 * b;
24
25
26
// linear interpolate ( yyy ) ( rgb )
r = (int) (y + s * (r - y));
27
g = (int) (y + s * (g - y));
28
b = (int) (y + s * (b - y));
29
30
31
// reassemble color pixel
c = ((r & 0xff)<<16) | ((g & 0xff)<<8) | b & 0xff;
32
ip.putPixel(u, v, c);
33
}
34
}
35
}
36
37
38
public int setup(String arg, ImagePlus imp) {
return DOES_RGB;
39
}
40
41
42 }
Search WWH ::




Custom Search