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.
I want it to be more like
not like this from opencv
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<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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With