Contour width measurement along its entire lendth

心不动则不痛 提交于 2019-12-06 00:53:04

I think distanceTransform(of OpenCV) and skeleton(maybe by yourself) will work.

Main idea:

  1. Threshold you gray image, then do distanceTransform to get dist-map
  2. Find the skeleton of the dist-map, the width is twice of the skeleton value.

The distance map is as follow.

Then you try to find the skeleton, double the dist value to get the width.


Update with C++ code:

int main() {
    // read as gray and threshold 
    Mat gray, threshed, dist;
    gray = imread("img01.png", 0);
    threshold(gray, threshed, 100, 255, THRESH_BINARY);
    imshow("threshed", threshed);

    //distanceTransform
    distanceTransform(threshed, dist, DIST_L2, 3);

    // normalize for display
    Mat dst;
    normalize(dist, dst, 255, 0, NORM_MINMAX,CV_8UC1);
    imshow("dst", dst);
    waitKey();

    return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!