OpenCV中此图像的前瞻性算法方法

时间:2014-12-01 07:51:12

标签: algorithm opencv computer-vision

我正在寻找具有丰富计算机视觉经验的人的建议。我有一组超声波B& W图像,如下图(没有星星和虚线):

ultrasonographic image of blood vessel

我想做的是检测血管的轮廓(例如,黄色星突出的血管)。当然,我的第一步是定义ROI并最大化对比度。但那么什么是最好的算法呢?使用分水岭算法进行分段?别的什么? 由于图像模糊,我感到很不安...


编辑:

根据评论中的要求,这里将是源图像和结果图像的示例: source result

1 个答案:

答案 0 :(得分:1)

如果我理解正确的话,以下是解决您问题的简单方法。我的结果如下所示。

The result of the code I have posted

这是代码

int max_area_threshold = 10000;
int min_area_threshold = 1000;
float rational_threshold = 0.7;

cv::Mat img = cv::imread("sample.jpg", CV_8UC1);
cv::Mat img_binary;

//Create binary imae by tresholding
cv::threshold(img, img_binary, 25, 255, CV_THRESH_BINARY);

//Invert black-white
cv::bitwise_not(img_binary, img_binary);

//Eliminating small segments
cv::erode(img_binary, img_binary, cv::Mat(), cv::Point(-1, -1), 2, 1, 1);
cv::dilate(img_binary, img_binary, cv::Mat(), cv::Point(-1, -1), 1, 1, 1);

//Find contours
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours( img_binary, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);

for( int i = 0; i< contours.size(); i++ )
{
    if(contours[i].size() < 5)
        continue;

    //Fit ellipse to contour
    cv::RotatedRect boundRect = cv::fitEllipse(contours[i]);

    //Check the squareness of the bounding box
    if(abs((boundRect.size.width / (float)boundRect.size.height)-1.0) > rational_threshold)
        continue;

    //Elliminate too big segments
    if(boundRect.boundingRect().area() > max_area_threshold)
        continue;

    //Elliminate too small segments
    if(boundRect.boundingRect().area() < min_area_threshold)
        continue;

    drawContours(img, contours, i, cv::Scalar(255), 0.2, 8, hierarchy, 0, cv::Point() );
}

cv::imwrite("result.jpg", img);

我希望它有所帮助。