Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在2D和3D模型中在MATLAB中绘制图像(.jpg)?

我有一个二维散点图,并且希望在原点显示图像(不是彩色正方形,而是实际图片)。有什么办法吗?

我还将绘制一个3-D球体,在该球体中我也希望在原点处显示图像。



回答:

对于二维绘图...

您正在寻找IMAGE功能。这是一个例子:

img = imread('peppers.png'); %# Load a sample image scatter(rand(1,20)-0.5,rand(1,20)-0.5); %# Plot some random data hold on; %# Add to the plot image([-0.1 0.1],[0.1 -0.1],img); %# Plot the image




对于3D图...

IMAGE功能不再适用,因为除非从正上方(即,沿Z轴正方向)观看轴,否则不会显示图像。在这种情况下,您将必须使用SURF函数在3-D中创建一个表面,然后将图像纹理映射到该表面上。这是一个例子:

[xSphere,ySphere,zSphere] = sphere(16); %# Points on a sphere scatter3(xSphere(:),ySphere(:),zSphere(:),'.'); %# Plot the points axis equal; %# Make the axes scales match hold on; %# Add to the plot xlabel('x'); ylabel('y'); zlabel('z'); img = imread('peppers.png'); %# Load a sample image xImage = [-0.5 0.5; -0.5 0.5]; %# The x data for the image corners yImage = [0 0; 0 0]; %# The y data for the image corners zImage = [0.5 0.5; -0.5 -0.5]; %# The z data for the image corners surf(xImage,yImage,zImage,... %# Plot the surface 'CData',img,... 'FaceColor','texturemap');

请注意,此表面固定在空间中,因此在旋转轴时,图像不一定总是直接面对相机。如果要使纹理贴图的表面自动旋转以使其始终垂直于相机的视线,则该过程将涉及更多的过程。



更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 20:35


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.