/Users/lyon/j4p/src/j2d/edge/LoGSobelProcessor.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 LoGSobelProcessor
14 implements ImageProcessorInterface,
15 ImageProcessorFactory {
16
17 private int kernelWidth;
18 private double sigma;
19 private int thresh = 128;
20 private boolean isThresh = true;
21 private boolean isSobel = true;
22
23
24 public LoGSobelProcessor(
25 int _kernelWidth,
26 double _sigma,
27 int _thresh,
28 boolean _isThresh,
29 boolean _isSobel) {
30
31 kernelWidth = _kernelWidth;
32 sigma = _sigma;
33 thresh = _thresh;
34 isThresh = _isThresh;
35 isSobel = _isSobel;
36 }
37
38 public ImageProcessorInterface getProcessor(int i) {
39 return
40 new LoGSobelProcessor(
41 kernelWidth,
42 i + 1,
43 thresh,
44 isThresh, isSobel);
45 }
46
47 public Image process(Image img) {
48 return LoGSobel(img);
49
50 }
51
52 private Image LoGSobel(Image img) {
53 System.out.println(
54 "kw=" + kernelWidth +
55 " sigma=" + sigma);
56 ThresholdProcessor tp = new ThresholdProcessor(thresh);
57 ImageProcessorInterface invert = InvertFilter.getProcessor();
58 Image logImage = ImageUtils.convolution(img,
59 Kernels.getLaplaceOfGaussianKernel(
60 kernelWidth,
61 kernelWidth,
62 sigma));
63 if (isThresh) logImage = tp.process(logImage);
64 return
65 invert.process(sobelImage(logImage));
66 }
67
68 private Image sobelImage(Image logImage) {
69 if (isSobel)
70 return ImageUtils.convolution(logImage,
71 Kernels.getSobel());
72 return logImage;
73 }
74
75 }
76
77