Hi Mohamed,
When working with heatmaps for data analysis, I've had similar experiences where MATLAB made the process much more manageable. Below, I've provided a sample code that can be used for the task. Feel free to adapt its individual components for other needs as well.
heatmapImage = imread('your_heatmap_image.png');
if size(heatmapImage, 3) == 3
heatmapImage = rgb2gray(heatmapImage);
normalizedHeatmap = normalize(double(heatmapImage));
imshow(normalizedHeatmap, []);
title('Normalized Heatmap');
binaryImage = imbinarize(normalizedHeatmap);
stats = regionprops(binaryImage, 'Area', 'Perimeter', 'BoundingBox', 'Centroid');
rectangle('Position', stats(k).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 1);
title('Extracted Shapes');
The result for the given image is as follows:
There are multiple functions used here, you can explore the same using the following commands:
- “doc normalize”
- “doc imbinarize”
- “doc regionprops”
I hope this helps with your issue.