18 #ifndef PIC_FEATURES_MATCHING_CANNY_EDGE_DETECTOR_HPP 19 #define PIC_FEATURES_MATCHING_CANNY_EDGE_DETECTOR_HPP 21 #include "../util/vec.hpp" 22 #include "../util/std_util.hpp" 23 #include "../image.hpp" 25 #include "../filtering/filter_luminance.hpp" 26 #include "../filtering/filter_gaussian_2d.hpp" 27 #include "../filtering/filter_gradient.hpp" 124 int dx0[] = {1, 1, 0, -1, 1};
125 int dy0[] = {0, 1, 1, 1, 0};
127 int dx1[] = {-1, -1, 0, 1, -1};
128 int dy1[] = { 0, -1, -1, -1, 0};
130 for(
int i = 0; i < grad->
height; i++) {
131 for(
int j = 0; j < grad->
width; j++) {
133 float *tmp_grad = (*grad)(j, i);
135 float angle = atan2(tmp_grad[1], tmp_grad[0]);
137 angle =
Rad2Deg(angle < 0.0f ?
C_PI + angle : angle);
138 int k = int(
lround(angle / 45.0f));
140 bool bMax = (tmp_grad[2] > (*grad)(j + dx0[k], i + dy0[k])[2]) &&
141 (tmp_grad[2] > (*grad)(j + dx1[k], i + dy1[k])[2]);
167 float *imgOut_ji = (*imgOut)(j, i);
169 imgOut_ji[0] = bMax ? tmp_grad[2] : 0.0f;
174 for(
int i = 0; i < imgOut->
height; i++) {
175 for(
int j = 0; j < imgOut->
width; j++) {
176 float *imgOut_ji = (*imgOut)(j, i);
183 imgOut_ji[0] = imgOut_ji[0] >
threshold_1 ? 0.5f : 0.0f;
190 int x[] = {1, 1, 0, -1, -1, -1, 0, 1};
191 int y[] = {0, 1, 1, 1, 0, -1, -1, -1};
193 for(
int i = 0; i < imgOut->
height; i++) {
194 for(
int j = 0; j < imgOut->
width; j++) {
195 float *imgOut_ji = (*imgOut)(j, i);
197 if((imgOut_ji[0] > 0.4f) && (imgOut_ji[0] < 0.6f)) {
200 for(
int k = 0; k < 8; k++) {
201 float *imgOut_ji_xy = (*imgOut)(j + x[k], i + y[k]);
203 if(imgOut_ji_xy[0] > 0.9f) {
209 imgOut_ji[0] = bRemove ? 0.0f : 1.0f;
void update(float sigma=1.4f, float threshold_1=0.05f, float threshold_2=0.3f)
update
Definition: canny_edge_detector.hpp:77
Definition: filter_luminance.hpp:28
bool bLum
Definition: canny_edge_detector.hpp:37
void setZero()
setZero sets data to 0.0f.
int channels
Definition: image.hpp:80
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
PIC_INLINE long lround(double x)
lround rounds double numbers properly.
Definition: math.hpp:229
~CannyEdgeDetector()
Definition: canny_edge_detector.hpp:66
void release()
release frees allocated memory for this class.
Definition: canny_edge_detector.hpp:45
const float C_PI
Definition: math.hpp:50
float threshold_1
Definition: canny_edge_detector.hpp:40
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
static Image * execute(Image *imgIn, Image *imgOut, LUMINANCE_TYPE type=LT_CIE_LUMINANCE)
execute
Definition: filter_luminance.hpp:166
Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter_npasses.hpp:310
The Image class stores an image as buffer of float.
Definition: image.hpp:60
float sigma
Definition: canny_edge_detector.hpp:40
Image * allocateSimilarOne()
allocateSimilarOne creates an Image with similar size of the calling instance.
Image * execute(Image *img, Image *imgOut)
execute executes Canny edge detector on img and ouputs imgEdges as results.
Definition: canny_edge_detector.hpp:96
PIC_INLINE float Rad2Deg(float rad)
Rad2Deg converts angles expressed in radians into angles expressed in degrees.
Definition: math.hpp:292
Image * lum
Definition: canny_edge_detector.hpp:38
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
The FilterGradient class.
Definition: filter_gradient.hpp:30
The CannyEdgeDetector class.
Definition: canny_edge_detector.hpp:34
The FilterGaussian2D class.
Definition: filter_gaussian_2d.hpp:31
CannyEdgeDetector()
CannyEdgeDetector.
Definition: canny_edge_detector.hpp:58
float threshold_2
Definition: canny_edge_detector.hpp:40
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
Definition: filter_gradient.hpp:25