Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a HeatMap from blobs different sizes using C++

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 lighter variations. But keep in mind that the center of the bigger blob should be the hottest region. I think the blobs can be made more curvaceous using gaussian blur and thresholding them.

I used opencvs method like using distance transform and then using apply colormap. But this feels like its more like inverted circles like skeletons(thinning) of the blobs. I want a better gradient heat map.

enter image description here

I want it to be more like enter image description here

not like this from opencventer image description here

like image 551
Anubhav Rohatgi Avatar asked Feb 10 '23 03:02

Anubhav Rohatgi


1 Answers

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);

enter image description here

//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);

enter image description here

vector<vector<Point> > contours;
vector<Vec4i> 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);

enter image description here

like image 96
Balaji R Avatar answered Feb 19 '23 11:02

Balaji R