code_device/hgdriver/ImageProcess/ImageApplyBWBinaray.h

87 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ====================================================
* 功能:二值化处理
* 作者:刘丁维
* 生成时间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,从原来的51调整到25
* 版本号v1.3.2
* ====================================================
*/
#ifndef IMAGE_APPLY_BW_BINARAY_H
#define IMAGE_APPLY_BW_BINARAY_H
#include "ImageApply.h"
class 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 = 25, int constant = 5);
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