我能够使用 Matlab 拍摄图像并在其上叠加热图。
我遇到的问题是,图例上的颜色编码与地图上表示的值不匹配。
如果您在 1512x1080 的图像上运行下面的代码,您会注意到代码中使用的值与图例上分配的值不对应。
例如,当考虑像素位置 700,400 中的点时,由于其对应值为 0.3,因此预期会显示红色,然而,在生成的图像中,该点的颜色是蓝黄色。
为什么会这样,我该如何纠正?
代码如下:
%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;
我使用 Matlab 中的 UI 制作了自定义图例。
我不知道如何获取代码,它显示为 64x3 double
数组如下所示(对不起,我不知道如何在这里制作表格)
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
我使用的函数是在 GitHub 上找到的。链接如下:
https://github.com/sergeyk/vislab/blob/master/matlab/gbvs/util/heatmap_overlay.m