Commit 025f9965b56261bc0105bb1b575095b109daaf9f
1 parent
eb124bd3
Better thresholding
Showing
1 changed file
with
13 additions
and
4 deletions
openbr/plugins/imgproc/threshold.cpp
| @@ -16,22 +16,31 @@ class ThresholdTransform : public UntrainableTransform | @@ -16,22 +16,31 @@ class ThresholdTransform : public UntrainableTransform | ||
| 16 | { | 16 | { |
| 17 | Q_OBJECT | 17 | Q_OBJECT |
| 18 | 18 | ||
| 19 | - Q_ENUMS(Method) | ||
| 20 | Q_ENUMS(Type) | 19 | Q_ENUMS(Type) |
| 20 | + Q_PROPERTY(Type type READ get_type WRITE set_type RESET reset_type STORED false) | ||
| 21 | + Q_PROPERTY(bool otsu READ get_otsu WRITE set_otsu RESET reset_otsu STORED false) | ||
| 21 | Q_PROPERTY(int thresh READ get_thresh WRITE set_thresh RESET reset_thresh STORED false) | 22 | Q_PROPERTY(int thresh READ get_thresh WRITE set_thresh RESET reset_thresh STORED false) |
| 22 | Q_PROPERTY(int maxValue READ get_maxValue WRITE set_maxValue RESET reset_maxValue STORED false) | 23 | Q_PROPERTY(int maxValue READ get_maxValue WRITE set_maxValue RESET reset_maxValue STORED false) |
| 23 | 24 | ||
| 24 | - public: | 25 | +public: |
| 26 | + enum Type { Binary = THRESH_BINARY, | ||
| 27 | + BinaryInv = THRESH_BINARY_INV, | ||
| 28 | + Trunc = THRESH_TRUNC, | ||
| 29 | + ToZero = THRESH_TOZERO, | ||
| 30 | + ToZeroInv = THRESH_TOZERO_INV}; | ||
| 31 | + | ||
| 32 | +private: | ||
| 33 | + BR_PROPERTY(Type, type, Binary) | ||
| 34 | + BR_PROPERTY(bool, otsu, false) | ||
| 25 | BR_PROPERTY(int, thresh, 0) | 35 | BR_PROPERTY(int, thresh, 0) |
| 26 | BR_PROPERTY(int, maxValue, 255) | 36 | BR_PROPERTY(int, maxValue, 255) |
| 27 | 37 | ||
| 28 | - | ||
| 29 | void project(const Template &src, Template &dst) const | 38 | void project(const Template &src, Template &dst) const |
| 30 | { | 39 | { |
| 31 | dst = src; | 40 | dst = src; |
| 32 | 41 | ||
| 33 | Mat mask; | 42 | Mat mask; |
| 34 | - threshold(src, mask, thresh, maxValue, THRESH_BINARY+THRESH_OTSU); | 43 | + threshold(src, mask, thresh, maxValue, otsu ? type+THRESH_OTSU : type); |
| 35 | 44 | ||
| 36 | dst.file.set("Mask",QVariant::fromValue(mask)); | 45 | dst.file.set("Mask",QVariant::fromValue(mask)); |
| 37 | } | 46 | } |