我如何可以绘制在MATLAB的图像(.JPG)在两个2-D和3-D? [英] How can I plot an image (.jpg) in MATLAB in both 2-D and 3-D?

查看:1006
本文介绍了我如何可以绘制在MATLAB的图像(.JPG)在两个2-D和3-D?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个2-D散点图,并在原点我要显示的图像(不是一个丰富多彩的广场,但实际的图片)。有没有办法做到这一点?

I have a 2-D scatter plot and at the origin I want to display an image (not a colorful square, but an actual picture). Is there any way to do this?

我也将绘制一个三维球体中,我想的图像将在原点,以及显示。

I also will be plotting a 3-D sphere in which I would like an image to be displayed at the origin as well.

推荐答案

函数图片就是你要寻找的。这里有一个例子:

For 2-D plots...

The function IMAGE is what you're looking for. Here's an example:

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


借助图片功能不再适用,因为图像也不会被显示出来,除非轴线从正上方看(即从沿正z轴)。在这种情况下,你将不得不使用 SURF 的功能和纹理在三维创建曲面图像映射到它。这里有一个例子:

The IMAGE function is no longer appropriate, as the image will not be displayed unless the axis is viewed from directly above (i.e. from along the positive z-axis). In this case you will have to create a surface in 3-D using the SURF function and texture map the image onto it. Here's an example:

[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');

请注意,这面固定在空间,因此图像不会永远的直接的面向相机当你旋转轴。如果希望的纹理映射表面以自动转动,使得其总是垂直于视线的摄像机的线路,这是一个更复杂的过程。

Note that this surface is fixed in space, so the image will not always be directly facing the camera as you rotate the axes. If you want the texture-mapped surface to automatically rotate so that it is always perpendicular to the line of sight of the camera, it's a much more involved process.

这篇关于我如何可以绘制在MATLAB的图像(.JPG)在两个2-D和3-D?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆