MATLAB 中的纹理映射
我有 3D 空间中的点及其相应的 2D 图像点。如何利用 3D 点制作网格,然后对网格形成的三角形面进行纹理处理?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有 3D 空间中的点及其相应的 2D 图像点。如何利用 3D 点制作网格,然后对网格形成的三角形面进行纹理处理?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
请注意,您使用的函数
trisurf
最初尝试使用返回 patch 对象的句柄。如果您查看'FaceColor'
补丁对象的属性,可以看到没有'texturemap'
选项。该选项仅对'FaceColor'< 有效表面对象的/code>属性
。因此,您必须找到一种方法将三角形表面绘制为表面对象而不是补丁对象。有两种方法可以解决此问题:
如果您的数据位于统一网格中...
如果表面数据的坐标表示统一网格,使得
z
是一组矩形点,其范围为 < x 轴上的 code>xmin 到xmax
,y 轴上的ymin
到ymax
,您可以使用以下方式绘制它冲浪
而不是trisurf
:为了说明上面的结果代码中,我将数据初始化为
Z = Peaks;
,使用内置示例图像'peppers.png'
,并设置x
和y
值从 1 到 16。这导致了以下纹理映射表面:如果您的数据间隔不均匀...
如果您的数据间隔 不均匀...不规则间隔,您可以创建一组规则间隔的
X
和Y
坐标(正如我上面使用meshgrid
),然后使用其中一个函数griddata
或TriScatteredInterp
从不规则的Z
值的规则网格>z 值。我在我对另一个SO问题的回答中讨论了如何使用这两个函数。这是您使用TriScatteredInterp
发布的代码的改进版本(注意:从 R2013a 开始scatteredInterpolant
是推荐的替代方案):在这种情况下,您必须首先选择
N<的值/code> 和
M
表示矩阵Z
的大小。为了说明上述代码的结果,我按如下方式初始化了x
、y
和z
的数据,并使用了内置的在示例图像'peppers.png'
中:这导致了以下纹理映射表面:
请注意,表面拐角附近有锯齿状边缘。这些地方的点太少,
TriScatteredInterp
无法充分拟合插值曲面。因此,这些点的Z
值为nan
,导致表面点未被绘制。Note that the function
trisurf
that you were originally trying to use returns a handle to a patch object. If you look at the'FaceColor'
property for patch objects, you can see that there is no'texturemap'
option. That option is only valid for the'FaceColor'
property of surface objects. You will therefore have to find a way to plot your triangular surface as a surface object instead of a patch object. Here are two ways to approach this:If your data is in a uniform grid...
If the coordinates of your surface data represent a uniform grid such that
z
is a rectangular set of points that span fromxmin
toxmax
in the x-axis andymin
toymax
in the y-axis, you can plot it usingsurf
instead oftrisurf
:In order to illustrate the results of the above code, I initialized the data as
Z = peaks;
, used the built-in sample image'peppers.png'
, and set thex
andy
values to span from 1 to 16. This resulted in the following texture-mapped surface:If your data is non-uniformly spaced...
If your data are not regularly spaced, you can create a set of regularly-spaced
X
andY
coordinates (as I did above usingmeshgrid
) and then use one of the functionsgriddata
orTriScatteredInterp
to interpolate a regular grid ofZ
values from your irregular set ofz
values. I discuss how to use these two functions in my answer to another SO question. Here's a refined version of the code you posted usingTriScatteredInterp
(Note: as of R2013ascatteredInterpolant
is the recommended alternative):In this case, you have to first choose the values of
N
andM
for the size of your matrixZ
. In order to illustrate the results of the above code, I initialized the data forx
,y
, andz
as follows and used the built-in sample image'peppers.png'
:This resulted in the following texture-mapped surface:
Notice that there are jagged edges near the corners of the surface. These are places where there were too few points for
TriScatteredInterp
to adequately fit an interpolated surface. TheZ
values at these points are thereforenan
, resulting in the surface point not being plotted.如果您的纹理已经处于正确的几何形状中,您可以只使用常规的旧纹理映射。
纹理映射的 MathWorks 文档的链接:
http://www.mathworks。 com/access/helpdesk/help/techdoc/visualize/f0-18164.html#f0-9250
重新编辑:稍微更新了代码:
尝试这种方法(我刚刚让它工作)。
因此 [x,y,z] 是“表面”,或者更确切地说是一个矩阵,其中包含表面上的许多 (x,y,z) 形式的点。请注意,图像被拉伸以适合表面。
If your texture is already in the proper geometry you can just use regular old texture mapping.
The link to the MathWorks documentation of texture mapping:
http://www.mathworks.com/access/helpdesk/help/techdoc/visualize/f0-18164.html#f0-9250
Re-EDIT: Updated the code a little:
Try this approach (I just got it to work).
So [x,y,z] is the 'surface' or rather a matrix containing a number of points in the form (x,y,z) that are on the surface. Notice that the image is stretched to fit the surface.