Digital Signal Processing Reference
In-Depth Information
D.2.8 File ContourOverlay.java
D.2 Kombinierte
Regionenmarkierung-
Konturverfolgung
1 import ij.ImagePlus;
2 import ij.gui.ImageCanvas;
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Graphics;
6 import java.awt.Graphics2D;
7 import java.awt.Polygon;
8 import java.awt.RenderingHints;
9 import java.awt.Shape;
10 import java.awt.Stroke;
11
12 class ContourOverlay extends ImageCanvas {
13
private static final long serialVersionUID = 1L;
static float strokeWidth = 0.5f;
14
static int capsstyle = BasicStroke.CAP_ROUND;
15
static int joinstyle = BasicStroke.JOIN_ROUND;
16
static Color outerColor = Color.black;
17
static Color innerColor = Color.white;
18
static float[] outerDashing = {strokeWidth * 2.0f,
strokeWidth * 2.5f};
19
static float[] innerDashing = {strokeWidth * 0.5f,
strokeWidth * 2.5f};
20
static boolean DRAW_CONTOURS = true;
21
22
23
Shape[] outerContourShapes;
Shape[] innerContourShapes;
24
25
26
ContourOverlay(ImagePlus imp, ContourSet contours) {
super(imp);
27
outerContourShapes = contours.getOuterPolygons();
28
innerContourShapes = contours.getInnerPolygons();
29
}
30
31
32
public void paint(Graphics g) {
super.paint(g);
33
drawContours(g);
34
}
35
36
37
private void drawContours(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
38
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
39
40
41
// scale and move overlay to the pixel centers
g2d.scale(this.getMagnification(), this.getMagnification())
;
42
g2d.translate(0.5-this.srcRect.x, 0.5-this.srcRect.y);
43
44
45
if (DRAW_CONTOURS) {
Search WWH ::




Custom Search