What is the code for graphing a map like this?
이전 댓글 표시
답변 (1개)
Image Analyst
2020년 12월 14일
0 개 추천
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
Zainab Shawqi Almubarak
2020년 12월 14일
Image Analyst
2020년 12월 14일
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.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
