-
Notifications
You must be signed in to change notification settings - Fork 0
/
canny.h
64 lines (41 loc) · 1.64 KB
/
canny.h
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
53
54
55
56
57
58
59
60
61
62
63
64
#include "image.h"
#include "image_ops.h"
#include <string>
#include <functional>
#include <unordered_map>
enum BlurSetting: int {
NO_BLUR,
BLUR1, // gaussian kernel with a sigma of 1
BLUR1_4, // ~ sigma of 1.4
BLUR2 // ~ sigma of 2
};
void calcGrads(const Image& image, FloatImage *ixPtr, FloatImage *iyPtr,
FloatImage *magPtr,
std::function<float(float, float, float)> reduction,
BlurSetting blur=BLUR1,
std::unordered_map<BlurSetting, FloatImage> *cachePtr = nullptr);
/// Creates a color image where the color corresponds to grad direction and
/// brightness to magnitude (if provided).
FloatImage colorizeGrads(const FloatImage& ix, const FloatImage& iy, const FloatImage* magImage = nullptr);
float maxOrZero(float val, float nb1, float nb2);
void connectWeak(Image *linesPtr, const Image& weak);
/// Find edges using Canny's edge detection method.
class EdgeFinder {
public:
bool readImage(const std::string& path);
bool readImage(const uint8_t *ptr, int size);
void calcGrads(std::function<float(float, float, float)> reduction=maxAbsChannel,
BlurSetting blur = BLUR1_4);
void calcNonMaxSuppression(float th, float tl, bool keepGrayscale = false);
const FloatImage& getLines() const;
const FloatImage& getGradient() const;
const Image& getImage() const { return _image; }
private:
Image _image;
std::unordered_map<BlurSetting, FloatImage> _cache;
FloatImage _ix;
FloatImage _iy;
FloatImage _mag;
FloatImage _lines;
FloatImage _weak;
};