-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheatmap_overlay.m
32 lines (26 loc) · 926 Bytes
/
heatmap_overlay.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
% img = image on which to overlay heatmap
% heatmap = the heatmap
% (optional) colorfunc .. this can be 'jet' , or 'hot' , or 'flag'
function omap = heatmap_overlay(img ,heatmap, colorfun)
% if (ischar(class(img)))
% img = imread(img);
% end
% if (ischar(class(img)))
% img = double(img)/255;
% end
szh = size(heatmap);
szi = size(img);
if ( (szh(1)~=szi(1)) || (szh(2)~=szi(2)) )
heatmap = imresize( heatmap , [ szi(1) szi(2) ] , 'bicubic' );
end
if ( size(img,3) == 1 )
img = repmat(img,[1 1 3]);
end
if ( nargin == 2 )
colorfun = 'jet';
end
colorfunc = eval(sprintf('%s(50)',colorfun));
heatmap = double(heatmap) / max(heatmap(:));
omap = 0.8*(1-repmat(heatmap.^0.8,[1 1 3])).*double(img)/max(double(img(:))) + repmat(heatmap.^0.8,[1 1 3]).* shiftdim(reshape( interp2(1:3,1:50,colorfunc,1:3,1+49*reshape( heatmap , [ prod(size(heatmap)) 1 ] ))',[ 3 size(heatmap) ]),1);
omap = real(omap);
end