Generate a HeatMap from blobs different sizes using C++

后端 未结 1 1150
谎友^
谎友^ 2021-01-03 05:37

I want to obtain a heatmap from the attached image. The bigger blobs will have darker(red) regions and then slowly fade to lighter blue shades. The smaller blobs will have l

1条回答
  •  隐瞒了意图╮
    2021-01-03 06:20

    You can simply cycle through individual blobs to find the Individual blob Color Map. Here is a sample implementation.You can use whatever Color map as you like. Hope this helps!

    Mat mSource_Gray,mBlobHeatMap,mHeatMap;
    mSource_Gray= imread(FileName_S.c_str(),0);
    
    //Just making sure everything is binary
    threshold(mSource_Gray,mSource_Gray,254,255,THRESH_BINARY);
    imshow("Source Image",mSource_Gray);
    

    //Finding Distance Transform
    Mat mDist,mBlobDist;
    distanceTransform(mSource_Gray, mDist, CV_DIST_L2, 3);
    normalize(mDist, mDist, 0, 1., cv::NORM_MINMAX);
    mDist.convertTo(mDist,CV_8UC1,255,0);
    imshow("mDist",mDist);
    

    vector > contours;
    vector hierarchy;
    /// Find contours to Mask out the Individual Contours
    findContours( mSource_Gray, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
    /// Draw contours (Mask)
    Mat mBlobMask = Mat::zeros( mSource_Gray.size(), CV_8UC1 );
    for( size_t i = 0; i< contours.size(); i++ )
    {
        drawContours( mBlobMask, contours, (int)i, Scalar(255), -1);
        mDist.copyTo(mBlobDist,mBlobMask);
        applyColorMap(mBlobDist,mBlobHeatMap,COLORMAP_JET);
        GaussianBlur(mBlobHeatMap,mBlobHeatMap,Size(21,21),0,0);
        mBlobHeatMap.copyTo(mHeatMap,mBlobMask);
    }
    
    imshow("mHeatMap",mHeatMap);
    

    0 讨论(0)
提交回复
热议问题