In the previous post we discussed about how to download the Google static map and plot the marker on given lat-long on the map. This allows the map to be reused offline.
To move further, we explore how could we use the map to visualize data on it, such as the temperature or the rainfall on the static map.
From the previous post, we already obtained the location of our place of interest. Now we would like to plot some data over it, say the number of visitors on that location, here how we could do it.
What we already have:
- Google Static Map, saved in S
- The pixels location of the place of interest, x_c, y_c
- Number of visitors, r = 50
We will first write a function to create the map data for the data we want to visualize.
function [S,map] = create_contour(I,h,k) // This function is to assign values to the circles defined by the radius // I is the google static map // h and k are the pixel location for the place of interest // r is the quantity we want to visualize sz = size(I); S = zeros(sz(1),sz(2)); map = S; for r = 1:50 t = 0:0.01:2.*%pi; x = h + r*cos(t); y = k + r*sin(t); xy = floor([x' y']); ind = sub2ind([sz(1),sz(2)],xy(:,2),xy(:,1)); S(ind) = r; end map(S~=0) = (51-S(S~=0))./50; endfunction
Using the created map, visualize the data with contour plot:
x_c = 398; y_c = 304; [Si,map] = create_contour(S,x_c,y_c); imshow(S);xset("fpf"," ") contour(1:600,1:600,map',15,frameflag=0);
Contour Plot – Filled
Instead of using contour lines, we could also use the filled level curves.
scf();imshow(S); contourf(1:600,1:600,map',15);f=gcf(); f.color_map = jetcolormap(16);
Heatmap With Image Fusion
We could also “fuse” 2 images –> the google map and the contour map to create heatmap.
Sc = ind2rgb(round(map.*16+1),[[0 0 0];jetcolormap(16)]); S2 = im2double(S); J = imfuse(S2,Sc,'composite',0.5); scf();imshow(J);
The previous heatmap seems to be dark in the region not covered by the contour lines. Here how we could improve it by replacing those regions by the origianl google map pixels value.
ind = Sc(:,:,1)==0&Sc(:,:,2)==0&Sc(:,:,3)==0; ind2 = repmat(ind,[1 1 3]); J(ind2) = S2(ind2); scf();imshow(J);