用光模式移除背景进行分割
方法一:R = L - I
方法二:R = 255*( 1 - (I/L) )
光模式L :没有对象,只有背景
图像I
结果 R
Mat removeLight(Mat img, Mat pattern, int method)
{
Mat aux;
// if method is normalization
if(method == 1)
{
// Reequire change out image to 32 float for divison
Mat img32, pattern32;
img.converTo(img32, CV__32F);
pattern.convertTo(pattern32, CV_32F);
// Divide the image by the pattern
aux = 1 - (img32/pattern32);
}
else
{
// Convert 8 bits format and scale
aux = pattern - img;
}
return aux;
}
光模式的获取
大内核尺寸的模糊技术,常用于光学字符识别。
左为近似,右7为真实。
Mat calculateLightPattern(Mat img)
{
Mat pattern;
// Basic and effective way to calculate the light pattern from one image
blur(img, pattern, Size(img.cols/3, img.cols/3));
return pattern;
}
阈值化
固定阈值操作
double threshold();
自适应阈值操作
void adaptiveThreshold();