我有低对比度图像分割的问题。 任务是查找表面缺陷。它们是可见的(缺陷总是黑暗的区域),但图像的对比度非常低。 下面两个样本。低对比度图像分割
我试图提高对比度,然后tresholding:
Mat tmp1 = imread("C:\\framesRoi\\311.bmp",0);
stretchContrast(tmp1);
threshold(tmp1,tmp1,75,255,THRESH_BINARY);
其中拉伸对比IMPL:
int minValue = 255, maxValue = 0;
const int l = sourceImg.cols * sourceImg.rows * sourceImg.channels();
if(sourceImg.isContinuous())
{
uchar* ptr = sourceImg.ptr<uchar>(0);
for(int i = 0; i < l; ++i)
{
if(ptr[i] < minValue)
{
minValue = ptr[i];
}
if(ptr[i] > maxValue)
{
maxValue = ptr[i];
}
}
}
cout<<"min: "<<minValue<<";"<<"max value: "<<maxValue<<endl;
const int magicThreshold = 10;
if(sourceImg.isContinuous())
{
uchar* ptr = sourceImg.ptr<uchar>(0);
for(int i = 0; i < l; ++i)
{
ptr[i] = 255 * (ptr[i]-minValue)/(maxValue - minValue);
}
}
但这种方法失败了。有许多错误的检测,而不是检测所有的缺陷:
这里是拉链与测试帧:https://dl.dropboxusercontent.com/u/47015140/testFrames.rar
当你根据图像内容的对比度拉伸,你输了就要挑一个有用的阈值范围内。 – 2014-12-03 21:34:09
@MarkRansom:我应该怎么做? – krzych 2014-12-03 21:38:41
如果您知道缺陷总是会变暗,您可以在不改变对比度的情况下调整亮度,使明亮区域保持一致。你可以用最大值来做到这一点,尽管使用第90百分位左右,而不会受到噪音的影响。 – 2014-12-03 21:48:25