低对比度图像分割

问题描述 投票:13回答:3

我有低对比度图像分割的问题。任务是找到表面缺陷。它们是可见的(缺陷总是暗区)但图像的对比度非常低。以下两个样本。

我尝试过增强对比度然后进行阈值处理:

Mat tmp1 = imread("C:\\framesRoi\\311.bmp",0);
stretchContrast(tmp1);
threshold(tmp1,tmp1,75,255,THRESH_BINARY);

拉伸对比度的地方:

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

c++ opencv image-processing computer-vision
3个回答
8
投票

尝试使用聚类方法(如kmeans)按灰度级对图像进行聚类。下面我直接在图像上使用了kmeans而没有任何灰度级变换(使用3个簇给了我更好的结果)。您应该能够通过使用注释中概述的方法对预处理的图像进行聚类来改善结果。

由于kmeans的随机性,簇的形状可能略有不同。

现在,如果您拍摄聚类图像的连通分量并计算这些区域的平均灰度级,则缺陷的平均值应低于其他区域。

我在Matlab中进行了聚类。

im = imread('r2SOV.png');%Uy1Fq r2SOV
gr = im;
size = size(gr);

% perform closing using a 5x5 circular structuring element
sel = strel('disk', 2, 4);
mcl = imclose(gr, sel);
% cluster gray levels using kmeans: using 3 clusters
x = double(mcl(:));
idx = kmeans(x, 3);
cl = reshape(idx, size);

figure, imshow(label2rgb(cl))

4
投票

正如人们在评论中所说,你可以以负面的方式改变亮度并提高对比度。

此外,sharpen filter对你的情况也非常有用。你可以在OpenCV中做this


4
投票

我认为你应该尝试一个大窗口的adaptiveThreshold功能。

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc,char** argv )
{

    Mat im = imread("c:/data/img1.png",0);
    cv::namedWindow("ctrl");
    int win=62;
    int th=2100;
    cv::createTrackbar( "win", "ctrl", &win, 500);
    cv::createTrackbar( "th", "ctrl", &th, 10000);
    while(true)
    {
        Mat thresh;
        medianBlur(im,thresh,15);//helps smooth out smaller noises, which you could also remove by size instead of this way
        adaptiveThreshold(thresh,thresh,255,ADAPTIVE_THRESH_MEAN_C,THRESH_BINARY,win*2+1,(    th/1000.));
        imshow("thresh",thresh);
        if(waitKey(1)==27)
            exit(0);
    }
}

这里的所有结果(http://www.datafilehost.com/d/99e3d86c)您可能还想看看实现一堆自动阈值算法的imagej。我认为您需要的是将本地图像信息考虑在内的内容。

© www.soinside.com 2019 - 2024. All rights reserved.