What is the code for graphing a map like this?
Show older comments
Answers (1)
Image Analyst
on 14 Dec 2020
0 votes
You'd first need the map image, or the coordinates of the black outlines.
Then you'd need the (x,y) coordinate, and precipitation value of every place there is a colored spot on the left map.
Then you can use scatteredInterpolant. See attached demo.
2 Comments
Zainab Shawqi Almubarak
on 14 Dec 2020
Image Analyst
on 14 Dec 2020
Zianab, yes, that's a part of it. Here's the meat of the program:
%================================ MAIN PART RIGHT HERE ==============================================
% Create the scattered interpolant. x, y, and gray levels must be column vectors so use (:) to make them column vectors.
% And grayLevels must be double or else an error gets thrown.
F = scatteredInterpolant(xAll(:), yAll(:), double(grayLevelsAll(:)))
% The above line creates an interpolant that fits a surface of the form v = F(x,y).
% Vectors x and y specify the (x,y) coordinates of the sample points.
% v is a vector that contains the sample values associated with the points (x,y).
% Get a grid of points at every pixel location in the RGB image.
[xGrid, yGrid] = meshgrid(1:columns, 1:rows);
xq = xGrid(:);
yq = yGrid(:);
% Evaluate the interpolant at query locations (xq,yq).
vq = F(xq, yq);
fittedImage = reshape(vq, rows, columns);
%================================ END OF MAIN PART ==============================================
You can see that after you make the interpolant function, F, you have to feed it coordinates of the rectangular image so that you can get the values EVERYWHERE, not just at the training points.
Then you have an image of estimated precipitation values, "fittedImage", everywhere in the image. You could use ind2rgb() to transform it into a color map. Then you can either plot the country boundaries over the image with plot(), or you could examine a separate country image and wherever there is a black pixel, set the interpolation image to black at those locations -- this will "burn" the country boundaries into the colored precipitation image.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!