简体   繁体   中英

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) .

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?

Thanks for any answers

If you have the pionts as cartesian coordinates use 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

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. 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)

[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. 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. Example: the following is the output of parula(4) , which can be manually input by replacing the line of code.

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

示例输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM