/Users/lyon/j4p/src/j2d/edge/MehrotraAndZhangProcessor.java
|
1 package j2d.edge;
2
3 import j2d.ImageUtils;
4 import ip.transforms.Kernels;
5 import j2d.ImageProcessorInterface;
6 import j2d.ImageProcessorFactory;
7 import j2d.hpp.InvertFilter;
8 import j2d.hpp.ThresholdProcessor;
9
10 import java.awt.*;
11
12
13 public class MehrotraAndZhangProcessor
14 implements ImageProcessorInterface,
15 ImageProcessorFactory {
16
17 private int kernelWidth;
18 private double h;
19
20
21 public MehrotraAndZhangProcessor(
22 int _kernelWidth,
23 double _h) {
24
25 kernelWidth = _kernelWidth;
26 h = _h;
27 }
28
29 public ImageProcessorInterface getProcessor(int i) {
30 return
31 new MehrotraAndZhangProcessor(
32 kernelWidth,
33 i);
34 }
35
36 public Image process(Image img) {
37 return MehrotraAndZhang(img);
38
39 }
40
41 private Image MehrotraAndZhang(Image img) {
42 System.out.println(
43 "kw=" + kernelWidth +
44 " h=" + h);
45 ThresholdProcessor thresh = new ThresholdProcessor(128);
46 ImageProcessorInterface invert = InvertFilter.getProcessor();
47 Image mzImage = ImageUtils.convolution(img,
48 Kernels.getMehrotraAndZhangKernel(
49 kernelWidth,
50 kernelWidth,
51 h));
52
53 mzImage = thresh.process(mzImage);
54 mzImage = ImageUtils.convolution(
55 mzImage,
56 Kernels.getSobel());
57
58
59 return invert.process(mzImage);
60 }
61
62 }
63
64