88 lines
2.3 KiB
C
88 lines
2.3 KiB
C
|
/*
|
|||
|
* ====================================================
|
|||
|
|
|||
|
* 功能:二值化处理
|
|||
|
* 作者:刘丁维
|
|||
|
* 生成时间: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
|
|||
|
2022/05/25 v1.3.3 调整blockSize和constant,对THRESH_BINARY同样有效
|
|||
|
* 版本号:v1.3.3
|
|||
|
|
|||
|
* ====================================================
|
|||
|
*/
|
|||
|
|
|||
|
#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 = 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
|
|||
|
|