Digital Signal Processing Reference
In-Depth Information
12.1
RGB-Farbbilder
1
// File
RGBbrighten2_.java
2
import ij.ImagePlus;
3
import ij.plugin.filter.PlugInFilter;
4
import ij.process.ColorProcessor;
5
import ij.process.ImageProcessor;
6
7
public class RGBbrighten2_ implements PlugInFilter {
8
Programm 12.2
Verarbeitung von RGB-Farbbildern
ohne Bitoperationen (ImageJ-Plugin,
Variante 2). Das Plugin erhoht
alle drei Farbkomponenten um 10
Einheiten und verwendet dafur
die erweiterten Zugriffsmethoden
getPixel(int, int, int[])
und
putPixel(int, int, int[])
der
Klasse
ColorProcessor
(Zeile 17 bzw.
21). Die Laufzeit ist aufgrund der
Methodenaufrufe ca. viermal hoher
als fur Variante 1 (Prog. 12.1).
static final int R = 0, G = 1, B = 2;
// component indices
9
10
public void run(ImageProcessor ip) {
//make sure image is of type ColorProcessor
11
ColorProcessor cp = (ColorProcessor) ip;
12
int[] RGB = new int[3];
13
14
15
for (int v = 0; v < cp.getHeight(); v++) {
for (int u = 0; u < cp.getWidth(); u++) {
16
cp.getPixel(u, v, RGB);
17
RGB[R] = Math.min(RGB[R]+10, 255);
// add 10 and
18
RGB[G] = Math.min(RGB[G]+10, 255);
// limit to 255
19
RGB[B] = Math.min(RGB[B]+10, 255);
20
cp.putPixel(u, v, RGB);
21
}
22
}
23
}
24
25
26
public int setup(String arg, ImagePlus imp) {
return DOES_RGB;
// this plugin works on RGB images
27
}
28
29
}
•
BMP
,
JPEG
:3
×
8-Bit-RGB.
•
PNG
(nur lesen): 3
×
8-Bit-RGB.
RAW
: Uber das ImageJ-Menu
File
•
Raw...
konnen RGB-
Bilddateien geoffnet werden, deren Format von ImageJ selbst nicht
direkt unterstutzt wird. Dabei ist die Auswahl unterschiedlicher An-
ordnungen der Farbkomponenten moglich.
→
Import
→
Erzeugen von RGB-Bildern
Ein neues RGB-Farbbild erzeugt man in ImageJ am einfachsten durch
Anlegen eines Objekts der Klasse
ColorProcessor
, wie folgendes Bei-
spiel zeigt:
1
int w = 640, h = 480;
2
ColorProcessor cproc = new ColorProcessor(w,h);
3
ImagePlus cwin = new ImagePlus("My New Color Image", cproc);
4
cwin.show();
Wenn erforderlich, kann das Farbbild nachfolgend durch Erzeugen eines
zugehorigen
ImagePlus
-Objekts (Zeile 3) und Anwendung der
show()
-