簡體   English   中英

Matlab中的3D眼圖

[英]3D eye figure in Matlab

您好,我在墊子實驗室中研究過眼睛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)

這是我嘗試過的代碼,但仍未達到我的期望

3D眼

您的問題根本沒有明確定義。 例如,您的輸出有什么不好?

  • 眼睛的形狀是什么?
  • 最終渲染(顏色,光線等...)?

我什至不問您對所需3D模型的定義。 在可以切割橫截面的完整3D模型和適合3D可視化的3D外表面之間,我想您是在談論后者(對於第一種方法,方法將完全不同)。

關於最終的輸出渲染,我可以給出一些有關如何使用紋理映射的指針,這對於此類項目非常有用。

我可以在Google上找到的帶有第一個紋理的簡單紋理映射可以為您提供這種結果: 三眼軟

三眼變紅

這是代碼(請注意,我對球體的定義與您的定義略有不同,但這只是個人選擇)

%% // 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'); 

請注意,對於虹膜,我從一個半球開始,然后在Y方向上進行壓縮(並將其平移到主球體的外表面上)。 這樣可以更好地渲染紋理映射。

您有兩個表面,現在應用紋理映射可以很簡單(我將舉一個簡單的例子)到非常繁瑣的工作……這取決於所需的結果和您必須使用的圖像。

對於第一個示例,我將使用2張圖像,其中一張用於眼球,另一張用於虹膜。 圖片將在帖子末尾提供。

%% 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)

使用相同的形狀(表面)但使用不同的紋理,可以獲得視覺上完全不同的結果。 例如:

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

將為您提供上述第二套示例。 請注意,在應用它們之前,我是如何復制紋理數據的,它允許圍繞眼睛重復圖案,而不僅僅是重復一次。 您可以使用nrep重復因子來獲得不同的結果。


如果要使虹膜更突出,可以使用定義yi的線的變體(即球體被壓縮和偏移的位置)。 例如,使用另一種紋理和這一行:

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

由此產生的虹膜稍微突出一些:

在此處輸入圖片說明


這里提供了用於紋理的圖像。 互聯網上有成千上萬的圖像可以提供更好的結果。 無論是合成圖像(純計算機圖形)還是真實的眼睛/虹膜圖片,只要注意許多圖像可能都具有版權,您就必須尊重...

你想要這樣的東西嗎?

某人的眼睛

[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