我有低對比度圖像分割的問題。 任務是查找表面缺陷。它們是可見的(缺陷總是黑暗的區域),但圖像的對比度非常低。 下面兩個樣本。低對比度圖像分割
我試圖提高對比度,然後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