% 读取图象数据到矩阵 [A, map] = imread('E:\\test.jpg'); % 得到图象信息 info = imfinfo('E:\\test.jpg'); w = info.Width; h = info.Height; % 创建与图象大小相对应的网格 [x,y] = meshgrid(1:w,1:h); z = x - y + y - x; i = 1; j = 1; % 用图象灰度值填充高度值 while (i - 1) * w + j <= w * h z(i,j) = A(i,j); j = j + 1; if j > w j = 1; i = i + 1; end end; % 绘制三维图象 meshc(x,y,z); % 绘制表面 surf(x,y,z,'FaceColor','interp','EdgeColor','none','FaceLighting','phong')