简体   繁体   English

Matlab中的3D眼图

[英]3D eye figure in Matlab

Hello every one i have been working on an eye 3D model in mat lab and all i have come up with is a flattened sphere, what should i add to it to make a realistic eye model? 您好,我在垫子实验室中研究过眼睛3D模型的每个人,我想出的只是一个扁平的球体,我应该在其中添加什么才能制作出逼真的眼睛模型?

[x,y,z] = sphere();
r = 5;
surf( r*x, r*y, r*z+2, 'edgecolor', 'none' )
axis equal, grid off, axis off

hold on
[x,y,z] = sphere;      
x = x(15:end,:);       
y = y(15:end,:);       
z = z(15:end,:);      
rx = 4;ry = 4;rz = 8;  
surf(rx*x,ry*y,rz*z);  
axis equal;  

set(gcf, 'Renderer', 'OpenGL');
shading interp, material shiny, lighting phong, lightangle(0, 55)

This is the code of what I have tried but still not close to what I expect 这是我尝试过的代码,但仍未达到我的期望

3D眼

Your question is not well defined at all. 您的问题根本没有明确定义。 For example what is not good with your output ? 例如,您的输出有什么不好?

  • The shape of the eye ? 眼睛的形状是什么?
  • The final rendering (color, light etc ...) ? 最终渲染(颜色,光线等...)?

And I'm not even asking your definition of the desired 3D model. 我什至不问您对所需3D模型的定义。 Between a full 3D model where you can cut cross sections and a 3D outside surface surface suitable for 3D visualization, I guess you are talking about the later (the approach would be completely different for the first option). 在可以切割横截面的完整3D模型和适合3D可视化的3D外表面之间,我想您是在谈论后者(对于第一种方法,方法将完全不同)。

Regarding the final output rendering, I can give a few pointers on how to use texture mapping ... very useful feature for these kind of project. 关于最终的输出渲染,我可以给出一些有关如何使用纹理映射的指针,这对于此类项目非常有用。

Simple texture mapping with the first textures I could find on google can give you this kind of result: 我可以在Google上找到的带有第一个纹理的简单纹理映射可以为您提供这种结果: 三眼软

三眼变红

Here's the code (note that I define my spheres slightly differently than you but that's just a personal choice) : 这是代码(请注意,我对球体的定义与您的定义略有不同,但这只是个人选择)

%% // generate unit sphere and prepare figure
[x,y,z] = sphere();
hf=figure('Color','w') ;
axis equal, grid off , axis off , hold on

%% // Define the main globe coordinate and generate surface
rMain = 5;
xm = x*rMain ;
ym = y*rMain ;
zm = z*rMain ;
mainGlobe =  surf( xm, ym, zm, 'edgecolor', 'none' ,'FaceAlpha',0.5 ) ;

%% // Define the Iris sphere and generate surface
rIris = 2.5 ;
cutoff = ceil(size(x,1)/2) ; %// calculated to get a half sphere (better result for later texture mapping)
xi = x(:,cutoff:end) * rIris ;       
yi = y(:,cutoff:end) * rIris /3 + (rMain-rIris)*1.7 ;       
zi = z(:,cutoff:end) * rIris  ;
irisGlobe = surf( xi, yi, zi , 'edgecolor', 'none'); 

Notice that for the Iris, i start with a half sphere, which I then compress in the Y direction (and translate to position it on the outside surface of the main globe). 请注意,对于虹膜,我从一个半球开始,然后在Y方向上进行压缩(并将其平移到主球体的外表面上)。 This produce better rendering of the texture mapping. 这样可以更好地渲染纹理映射。

You've got two surface, now applying texture mapping can be anything from very straightforward (I'll give a simple example) to quite tedious ... depending on the desired result and the images you have to work with. 您有两个表面,现在应用纹理映射可以很简单(我将举一个简单的例子)到非常繁琐的工作……这取决于所需的结果和您必须使用的图像。

For the first example I'll use 2 images, one for the eye globe and one for the Iris. 对于第一个示例,我将使用2张图像,其中一张用于眼球,另一张用于虹膜。 The images will be available at the end of the post. 图片将在帖子末尾提供。

%% Apply texture mappings
imgIris = imread('Iris03.jpg') ;   %// read Iris texture image
imgGlobe = imread('globe02.jpg') ; %// read Globe texture image

%// (optional) mirror globe image to repeat pattern (and increase definition)
CDglobe = [imgGlobe flipdim(imgGlobe,2)] ;

%// apply mapping
set(mainGlobe,'FaceColor','Texturemap','Cdata',CDglobe,'FaceAlpha',0.5)
set(irisGlobe,'FaceColor','Texturemap','Cdata',imgIris,'edgecolor', 'none')

%// texture mapping in default direction produce blood vessel in `Z`
%// direction mainly, so to have them departing from the Iris, we just
%// rotate the main globe by 90 degree (or we could also rotate the
%// image beforehand ...)
rotate(mainGlobe,[1 0 0],-90)

With the same shapes (surfaces) but different textures, you can get quite visually different results. 使用相同的形状(表面)但使用不同的纹理,可以获得视觉上完全不同的结果。 For example: 例如:

imgIris = imread('Iris01.jpg') ;   %// read Iris texture image
imgGlobe = imread('globe01.jpg') ; %// read Globe texture image

%// mirror globe image to repeat pattern (and increase definition)
nrep = 3 ;
CDglobe = repmat( [imgGlobe flipdim(imgGlobe,2)], [1 nrep 1]) ;

%// apply mapping
set(mainGlobe,'FaceColor','Texturemap','Cdata',CDglobe,'FaceAlpha',0.5)
set(irisGlobe,'FaceColor','Texturemap','Cdata',imgIris,'edgecolor', 'none')

will get you the second set of eye example above. 将为您提供上述第二套示例。 Notice how I replicated the texture data before applying them, it allows to repeat the pattern around the eye instead of having it only once. 请注意,在应用它们之前,我是如何复制纹理数据的,它允许围绕眼睛重复图案,而不仅仅是重复一次。 You can play with the nrep repetition factor for varying results. 您可以使用nrep重复因子来获得不同的结果。


If you want a more protuberant Iris, you can use a variation of the line where yi is defined (that's where the sphere is compressed and offseted). 如果要使虹膜更突出,可以使用定义yi的线的变体(即球体被压缩和偏移的位置)。 For example, with another texture and this line : 例如,使用另一种纹理和这一行:

yi = y(:,cutoff:end) * rIris  + (rMain-rIris)*1.7 - 1.1 ;

The resulting Iris is slightly more prominent: 由此产生的虹膜稍微突出一些:

在此处输入图片说明


The images used for texture are given here. 这里提供了用于纹理的图像。 There are a gazillion images available on internet which will give even better result. 互联网上有成千上万的图像可以提供更好的结果。 Whether it's synthetic images (pure computer graphics) or real eye/iris pictures, just pay attention that many images may have a copyright which you will have to respect ... 无论是合成图像(纯计算机图形)还是真实的眼睛/虹膜图片,只要注意许多图像可能都具有版权,您就必须尊重...

Do you want something like this? 你想要这样的东西吗?

某人的眼睛

[x, y, z] = sphere();
r = 5;
eballcolor = ones([size(x) 3]);
surf(r*x, r*y, r*z+2, eballcolor, 'edgecolor', 'none');
hold on;
[x, y, z] = sphere();
x = x(15:end,:);
y = y(15:end,:);
z = z(15:end,:);
rx = 4; ry = 4; rz = 8;
corneacolor = zeros([size(x) 3]);
surf(rx*x, ry*y, rz*z, corneacolor);
grid off
axis off
axis equal;
axis vis3d;

set(gcf, 'Renderer', 'OpenGL');
shading interp, material shiny, lighting phong, lightangle(0, 55);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM