[英]How to plot height information in Matlab using surf?
I have obtained the latitude, longitude and height information from a TIFF image into Matlab and plotting it using the surfc
function as surfc(X,Y,Z)
. 我已经将TIFF图像中的纬度,经度和高度信息获取到Matlab中,并使用surfc
函数作为surfc(X,Y,Z)
绘图。
surfc
output: surfc
输出:
Image of the tree: 树的形象:
But how do I get Z to display as a contour (something like a cone) corresponding to the height of an object in the image? 但是如何让Z显示为与图像中对象高度相对应的轮廓(像锥形) ?
Thanks for any answers 谢谢你的回答
If you have the pionts as cartesian coordinates use plot3
如果你有plot3
作为笛卡尔坐标使用plot3
plot3(X,Y,Z,'.');
If X and Y are the independent variables and Z the dependent one (The corresponding height for a given X and Y) then use surf
or mesh
如果X和Y是自变量而Z是从属变量(给定X和Y的相应高度)则使用surf
或mesh
surf(X,Y,Z);
mesh(X,Y,Z);
Otherwise put some sample of your data and results so we can better understand your problem. 否则,请提供一些数据样本和结果,以便我们更好地了解您的问题。
EDIT: You are actually obtaining a contour plot, but surfc
should also plot the surface. 编辑:你实际上是在获得等高线图,但是surfc
也应该绘制表面。 Take a look at the documentation of surfc
and you will see that it combines two plots in one figure (the surface and the contour) 看一下surfc
的文档 ,你会看到它在一个图中组合了两个图(表面和轮廓)
[X,Y,Z] = peaks(30);
figure
surfc(X,Y,Z)
You can change the color mapping of the surf. 您可以更改冲浪的颜色映射。 Example: 例:
clear;clc;close all
tif4 = imread('RzwK3.tif');
THeight = rgb2gray(tif4(:,:,1:3));
imshow(THeight)
x = 1:size(THeight,1); % can be changed to coordinates
y = 1:size(THeight,2);
[X,Y] = ndgrid(x,y);
% make contour color on the surface
M = 4; % # color in contour
Cvec = parula(M); % any Mx3 RGB triplet
hs = surf(X,Y,THeight,'EdgeAlpha',.1);
colormap(Cvec)
colorbar
If parula
or other color generation function is not available in your Matlab version, you can assign Cvec
manually. 如果您的Matlab版本中没有parula
或其他颜色生成功能,您可以手动分配Cvec
。 Each row of the matrix is a RGB color triplet with values between 0 and 1 (you can divide a web RGB color by 256) and there should be M
rows in the matrix. 矩阵的每一行都是RGB颜色三元组,其值介于0和1之间(您可以将Web RGB颜色除以256)并且矩阵中应该有M
行。 Example: the following is the output of parula(4)
, which can be manually input by replacing the line of code. 示例:以下是parula(4)
的输出,可以通过替换代码行手动输入。
Cvec = [
0.2081 0.1663 0.5292; % R1 G1 B1
0.0265 0.6137 0.8135; % R2 G2 B2
0.6473 0.7456 0.4188; % R3 G3 B3
0.9763 0.9831 0.0538]; %R4 G4 B4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.