PDA

查看完整版本 : 如何在2D和3D模型中在MATLAB中绘制图像(.jpg)?


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

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



回答:

对于二维绘图...

您正在寻找IMAGE (http://www.mathworks.com/help/techdoc/ref/image.html)功能。这是一个例子:

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 https://i.stack.imgur.com/sKh07.png




对于3D图...

IMAGE (http://www.mathworks.com/help/techdoc/ref/image.html)功能不再适用,因为除非从正上方(即,沿Z轴正方向)观看轴,否则不会显示图像。在这种情况下,您将必须使用SURF (http://www.mathworks.com/help/techdoc/ref/surf.html)函数在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'); https://i.stack.imgur.com/8j3Bd.png

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



更多&回答... (https://stackoverflow.com/questions/3719502)