code_device/hgdriver/ImageProcess/ImageApplyBWBinaray.h

89 lines
2.5 KiB
C
Raw Permalink Normal View History

2022-07-29 08:41:34 +00:00
/*
* ====================================================
*
*
* 2020/4/21
* 2020/5/28 v1.1
2020/5/29 v1.2
2020/6/19 v1.3
2020/12/21 v1.3.1
2020/12/21 v1.3.2 blockSize,5125
2022/05/25 v1.3.3 blockSize和constantTHRESH_BINARY同样有效
2023/11/22 v1.4 THRESH_BINARY模式时m_threshold作为THRESHOLD_LOW使用
* v1.4
2022-07-29 08:41:34 +00:00
* ====================================================
*/
#ifndef IMAGE_APPLY_BW_BINARAY_H
#define IMAGE_APPLY_BW_BINARAY_H
#include "ImageApply.h"
class GIMGPROC_LIBRARY_API CImageApplyBWBinaray:public CImageApply
{
public:
enum class ThresholdType
{
THRESH_BINARY = 0, //传统二值化
THRESH_OTSU, //大津阈值
ADAPTIVE_GAUSSIAN, //高斯局部自适应阈值
ADAPTIVE_MEAN, //均值局部自适应阈值
ERROR_DIFFUSION //错误扩散
};
/*
* type [in]:
* threshold [in]:THRESH_OTSU时无效
* blockSize [in]:ADAPTIVE_GAUSSIAN和ADAPTIVE_MEAN模式有效
* constant [in]:ADAPTIVE_GAUSSIAN和ADAPTIVE_MEAN模式有效blockSize形成比例关系
*/
CImageApplyBWBinaray(ThresholdType type, int threshold = 120, int blockSize = 51, int constant = 41);
CImageApplyBWBinaray();
virtual ~CImageApplyBWBinaray(void);
virtual void apply(cv::Mat& pDib,int side);
virtual void apply(std::vector<cv::Mat>& mats, bool isTwoSide);
double getThreshold() { return m_threshold; }
ThresholdType getThresholdType() { return m_type; }
int getBlockSize() { return m_blockSize; }
double getConstant() { return m_constant; }
void setThreshold(double value) { m_threshold = value; }
void setThresholdType(ThresholdType type) { m_type = type; }
void setBlockSize(int value) { m_blockSize = value; }
void setConstant(double value) { m_constant = value; }
private:
void errorDiffuse(cv::Mat& image);
private:
double m_threshold;
ThresholdType m_type;
int m_blockSize;
double m_constant;
uchar* m_table;
};
#endif //!IMAGE_APPLY_BW_BINARAY_H