# Wolfram 语言™

## 利用多个视图重建三维物体

In[1]:=

In[2]:=
`mask = Erosion[Binarize[imgs[[2]], 0], 1];`

In[3]:=
`parallaxL = First@ImageDisplacements[imgs[[{2, 1}]]];`
In[4]:=
`parallaxR = First@ImageDisplacements[imgs[[{2, 3}]]];`

In[5]:=
`parallax = parallaxL - parallaxR;`

In[6]:=
```depth = Blur@ Opening[ImageMultiply[ImageAdjust@Image[parallax[[All, All, 1]]], mask], DiskMatrix[4]]```
Out[6]=

In[7]:=
`depthFunction = ListInterpolation[Transpose@Reverse@ImageData[depth]];`

In[8]:=
`resolution = ImageAdjust@ImageSaliencyFilter[imgs[[2]]];`
In[9]:=
```resolutionFunction = ListInterpolation[Transpose@Reverse@ImageData@resolution];```
In[10]:=
```\[CapitalOmega] = TriangulateMesh[ ImageMesh[Erosion[mask, DiskMatrix[2]]], MeshRefinementFunction -> Function[{vertices, area}, area > 32 + 512 (1 - resolutionFunction @@ Mean[vertices])^6] ]```
Out[10]=

In[11]:=
```Graphics3D[ GraphicsComplex[ Apply[{##, depthFunction[##]} &, MeshCoordinates[\[CapitalOmega]], {1}], {EdgeForm[], MeshCells[\[CapitalOmega], 2]} ], PlotRange -> Append[Thread[{0, ImageDimensions[mask]}], {0, 1}], BoxRatios -> {1, 1, 2/3}, ViewPoint -> Top ]```
Out[11]=

In[12]:=
`texture = SetAlphaChannel[imgs[[2]], mask]`
Out[12]=

In[13]:=
```Graphics3D[ {Texture[texture], GraphicsComplex[ Apply[{##, depthFunction[##]} &, MeshCoordinates[\[CapitalOmega]], {1}], {EdgeForm[], MeshCells[\[CapitalOmega], 2]}, VertexTextureCoordinates -> Map[#/ImageDimensions[texture] &, MeshCoordinates[\[CapitalOmega]]] ] }, PlotRange -> Append[Thread[{0, ImageDimensions[mask]}], {0, 1}], BoxRatios -> {1, 1, 2/3}, Lighting -> {{"Ambient", White}}, ViewPoint -> Top, Boxed -> False ]```