Created
July 27, 2016 18:12
-
-
Save jabooth/3ed3746954c7b99179181a56eddf4617 to your computer and use it in GitHub Desktop.
Example of loading 3D data from .mat file into Menpo and converting to our types for landmarking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# All the imports we will need\n", | |
"import scipy.io as sio\n", | |
"import menpo3d.io as m3io\n", | |
"from menpo.landmark import LandmarkGroup\n", | |
"from menpo.shape import TriMesh, PointCloud" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['tri', 'vertex', '__header__', '__globals__', 'landmark', '__version__']\n" | |
] | |
} | |
], | |
"source": [ | |
"# 1. Load the mat file and extract what we need\n", | |
"d = sio.loadmat('./simple_F015_Happy_019_fit.mat')\n", | |
"print(d.keys())\n", | |
"\n", | |
"# extract the data we need\n", | |
"trilist = d['tri']\n", | |
"points = d['vertex']\n", | |
"lm_points = d['landmark']" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"TriMesh: n_points: 9909, n_dims: 3, n_tris: 19520\n", | |
"LandmarkGroup: n_labels: 1, n_points: 33\n" | |
] | |
} | |
], | |
"source": [ | |
"# 2. Build Menpo types for the Mesh and the landmarks\n", | |
"mesh = TriMesh(points, trilist=trilist)\n", | |
"landmarks = LandmarkGroup.init_with_all_label(PointCloud(lm_points))\n", | |
"\n", | |
"print(mesh)\n", | |
"print(landmarks)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# 3. Export the data as .obj and .ljson\n", | |
"m3io.export_mesh(mesh, './simple_F015_Happy_019_fit.obj')\n", | |
"m3io.export_landmark_file(landmarks, './simple_F015_Happy_019_fit.ljson')" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment