4

I have an image like this one Heatmap with original image as background and the corresponding background image. Original image

I am trying to extract the heatmap of the first image. My first approach was to mask every pixel that was not "equal enough" (thresholding the euclidean distance between every pixel), but the results were not good enough Mask

Looks like a straightforward problem in image processing, but I lack experience. Thanks!

2

1 Answer 1

4

Obtaining the exact heat map is a highly non-trivial problem since the heat map was superimposed with varying levels of transparency.
This means that per pixel there are two unknowns:

  1. The heat map itself and
  2. transparency (they are linked but the exact mapping is unknown).

If a rough segmentation suffices, I suggest a simple thresholding via the color intensities. You can see that the stronger regions of the heatmap are surrounded by a strong, blue color:

I = imread('https://i.stack.imgur.com/7oVZK.png');

% Simple, manual color thresholding
mask1 = I(:,:,3) > 230 & I(:,:,1) < 30 & I(:,:,2) < 10;

Now we dilate the mask to close any holes in the blue heat map boundaries and fill the holes:

% Morphological processing
mask2 = imdilate(mask1, strel('disk',5,0));
mask2 = imfill(mask2, 'holes');

Finally, we can extract the heat map:

% Extract heat map
heat_map = I;
heat_map(~repmat(mask2,[1 1 3])) = 255;
imshow(heat_map)

Here is the Result
enter image description here

Edit: If you have to process many similar images, it might be more robust to perform the segmentation in hsv space:

I_hsv = rgb2hsv(I);
mask1 = I_hsv(:,:,1) > 0.6 & I_hsv(:,:,1) < 0.7 & I_hsv(:,:,2) > 0.95 & I_hsv(:,:,3) > 0.9;
2
  • Thanks! By the way, could you explain more about segmentation in HSV space? Mar 5, 2017 at 1:16
  • Sure. If you want to use the blue color for segmentation (as presented), then the threshold values in RGB space will depend on the illumination (brightness). In HSV color space you can perform thresholding directly on the hue value with some constraints on saturation and value (shown in the last line of my answer).
    – Richard
    Mar 5, 2017 at 2:49

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.