-
Notifications
You must be signed in to change notification settings - Fork 0
/
MorphologyFilter.java
52 lines (43 loc) · 1.51 KB
/
MorphologyFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkg2014vision;
import org.bytedeco.javacpp.opencv_core.CvMat;
import org.bytedeco.javacpp.opencv_core.IplConvKernel;
import static org.bytedeco.javacpp.opencv_imgproc.cvDilate;
import static org.bytedeco.javacpp.opencv_imgproc.cvErode;
/**
*
* @author Jared "Jär Bär" Gentner
*/
public class MorphologyFilter extends FilterDecorator {
private boolean expand;
private int shape;
private int kernelwidth;
private int kernelheight;
public MorphologyFilter(Filter filter, int shape, int kernelwidth, int kernelheight, boolean expand) {
super(filter);
this.kernelwidth = kernelwidth;
this.kernelheight = kernelheight;
this.shape = shape;
this.expand = expand;
}
public MorphologyFilter(Filter filter, int shape, int kernelwidth, int kernelheight) {
this(filter, shape, kernelwidth, kernelheight, false);
}
@Override
protected CvMat decorateFilter(CvMat image) {
CvMat dest = image.clone();
IplConvKernel kernel = IplConvKernel.create(kernelheight, kernelwidth, 0, 0, shape, null);
if(expand){
cvDilate(dest, dest, kernel, 1);
cvErode(image, dest, kernel, 1);
}else{
cvErode(image, dest, kernel, 1);
cvDilate(dest, dest, kernel, 1);
}
return dest;
}
}