I was able to take an image and overlay a heat map on top of it using Matlab.
The problem I am having is, the color coding on the legend does not match the values represented on the map.
If you run the code below on an image that is 1512x1080 you will notice that the values used in code do not correspond to the values assigned on the legend.
As an example, when considering the point in the pixel location 700,400 one would expect a red color to display since its corresponding value is 0.3 however, in the image generated the color of that point is a blue-ish yellow.
Why is this, and how can I correct it?
The code is as follows:
%Import an image***********************************************
%Ask a user to import the image they want
%**************************************************************
%The commented out line will not show the file type when prompted to select
%an image
%[fn,pn] = uigetfile({'*.TIFF,*.jpg,*.JPG,*.jpeg,*.bmp','Image files'}, 'Select an image');
%This line will select any file type, want to restrict in future
[fn,pn] = uigetfile({'*.*','Image files'}, 'Select an image');
importedImage = imread(fullfile(pn,fn));
%Setting up the color map to use
ax = gca;
load('MyColormaps','mycmap');
colormap(ax,mycmap);
%Create size for heat map**************************************
%Setting the size for the map, see comments below
%**************************************************************
%What if I wanted an arbitrary dimension
%Or better yet, get the dimensions from the imported file
heatMap = zeros(1080,1512);
%Manually placing the heatmap values along a grid
%Want to set zones for this, maybe plot out in excel and use the cells to
%define the image size?
heatMap(84,328) = .38;
heatMap(132,385) = .42;
heatMap(86,418) = .40;
heatMap(405,340) = .60;
heatMap(263,515) = .35;
heatMap(480,627) = .40;
heatMap(673,800) = .28;
heatMap(598,892) = .38;
heatMap(540,1020) = .33;
heatMap(684,1145) = .38;
heatMap(275,912) = .44;
heatMap(185,798) = .54;
heatMap(700,400) = .3; %This is a testing point, not an actual value
%Generate the Map**********************************************
%Making the density and heat map
%**************************************************************
%Testing different filtering types
gaussiankernel = fspecial('gaussian', [350 350], 25);
%gaussiankernel = fspecial('average', [50 50]);
density = imfilter(heatMap, gaussiankernel, 'replicate');
%imshow(density, []);
oMask = heatmap_overlay(importedImage, density);
set(figure(1), 'Position', [0 0 1512 1080]);
imshow(oMask,[]);
colormap(mycmap);
colorbar;
I made the custom legend using the UI in Matlab.
I am not sure how to obtain the code, it is showing as a 64x3 double
The array is shown below (Sorry, I don't know how to make tables here)
0.00196078442968428 0.00196078442968428 1
0.107223942875862 0.00196078442968428 1
0.212487101554871 0.00196078442968428 1
0.317750245332718 0.00196078442968428 1
0.423013418912888 0.00196078442968428 1
0.528276562690735 0.00196078442968428 1
0.633539736270905 0.00196078442968428 1
0.738802909851074 0.00196078442968428 1
0.844066023826599 0.00196078442968428 1
0.949329197406769 0.00196078442968428 1
1 0.00196078442968428 0.949329197406769
1 0.00196078442968428 0.844066023826599
1 0.00196078442968428 0.738802909851074
1 0.00196078442968428 0.633539736270905
1 0.00196078442968428 0.528276562690735
1 0.00196078442968428 0.423013418912888
1 0.00196078442968428 0.317750245332718
1 0.00196078442968428 0.212487101554871
1 0.00196078442968428 0.107223942875862
1 0.00196078442968428 0.00196078442968428
1 0.0575163401663303 0.00196078442968428
1 0.113071896135807 0.00196078442968428
1 0.168627455830574 0.00196078442968428
1 0.224183008074760 0.00196078442968428
1 0.279738575220108 0.00196078442968428
1 0.335294127464294 0.00196078442968428
1 0.390849679708481 0.00196078442968428
1 0.446405231952667 0.00196078442968428
1 0.501960813999176 0.00196078442968428
1 0.557516336441040 0.00196078442968428
1 0.613071918487549 0.00196078442968428
1 0.668627440929413 0.00196078442968428
1 0.724183022975922 0.00196078442968428
1 0.779738545417786 0.00196078442968428
1 0.835294127464294 0.00196078442968428
1 0.890849649906158 0.00196078442968428
1 0.946405231952667 0.00196078442968428
1 1 0.00196078442968428
0.911051690578461 1 0.00196078442968428
0.820142626762390 1 0.00196078442968428
0.729233503341675 1 0.00196078442968428
0.638324439525604 1 0.00196078442968428
0.547415316104889 1 0.00196078442968428
0.456506252288818 1 0.00196078442968428
0.365597158670425 1 0.00196078442968428
0.274688065052032 1 0.00196078442968428
0.183778971433640 1 0.00196078442968428
0.0928698778152466 1 0.00196078442968428
0.00196078442968428 1 0.00196078442968428
0.00196078442968428 0.968496739864349 0.00196078442968428
0.00196078442968428 0.935032665729523 0.00196078442968428
0.00196078442968428 0.901568651199341 0.00196078442968428
0.00196078442968428 0.868104577064514 0.00196078442968428
0.00196078442968428 0.834640502929688 0.00196078442968428
0.00196078442968428 0.801176488399506 0.00196078442968428
0.00196078442968428 0.767712414264679 0.00196078442968428
0.00196078442968428 0.734248340129852 0.00196078442968428
0.00196078442968428 0.700784325599670 0.00196078442968428
0.00196078442968428 0.667320251464844 0.00196078442968428
0.00196078442968428 0.633856236934662 0.00196078442968428
0.00196078442968428 0.600392162799835 0.00196078442968428
0.00196078442968428 0.566928088665009 0.00196078442968428
0.00196078442968428 0.533464074134827 0.00196078442968428
0.00196078442968428 0.500000000000000 0.00196078442968428
The function I used was found on GitHub. The link to that is found below:
https://github.com/sergeyk/vislab/blob/master/matlab/gbvs/util/heatmap_overlay.m