Last active
February 3, 2017 15:41
-
-
Save Ghazi-Bouabene/0b297d10ce38c01cf73fbb85f8487ec6 to your computer and use it in GitHub Desktop.
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
val noseless = MeshIO.readMesh(new File("datasets/noseless.stl")).get | |
show(noseless,"noseless") | |
val littleModel = StatismoIO.readStatismoMeshModel(new File("datasets/model.h5")).get | |
show(littleModel, "littleModel") | |
val zeroMean = VectorField(RealSpace[_3D], (pt:Point[_3D]) => Vector(0,0,0)) | |
val scalarValuedKernel = GaussianKernel[_3D](30) * 10 | |
case class XmirroredKernel(ker : PDKernel[_3D]) extends PDKernel[_3D] { | |
override def domain = RealSpace[_3D] | |
override def k(x: Point[_3D], y: Point[_3D]) = ker(Point(x(0) * -1f ,x(1), x(2)), y) | |
} | |
def SymmetrizeKernel(ker : PDKernel[_3D]) : MatrixValuedPDKernel[_3D,_3D] = { | |
val xmirrored = XmirroredKernel(ker) | |
val k1 = DiagonalKernel(ker) | |
val k2 = DiagonalKernel(xmirrored * -1f, xmirrored, xmirrored) | |
k1 + k2 | |
} | |
val sim = SymmetrizeKernel(scalarValuedKernel) | |
val gp = GaussianProcess(zeroMean, sim) | |
val model = StatisticalMeshModel.augmentModel(littleModel, gp, 50) | |
show(model, "model") | |
remove("littleModel") | |
val lms = LandmarkIO.readLandmarksJson[_3D](new File("datasets/noseFittingLandmarks.json")).get | |
addLandmarksTo(lms, "noseless") | |
// execute this only if you were unable to click the landmarks | |
val lm = LandmarkIO.readLandmarksJson[_3D](new File("datasets/noseFittingModelLms.json")).get | |
addLandmarksTo(lm,"model") | |
val modelPts : Seq[Point[_3D]] = getLandmarksOf("model").get.map{lm => lm.point} | |
val noselessPts = getLandmarksOf("noseless").get.map{lm => lm.point} | |
val littleNoise = NDimensionalNormalDistribution(Vector(0,0,0), SquareMatrix((0.5f,0,0), (0,0.5f,0), (0,0,0.5f))) | |
val trainingData = (modelPts zip noselessPts).map{ case (mPt, nPt) => | |
(model.mean.findClosestPoint(mPt).id, nPt, littleNoise) | |
} | |
val posterior = model.posterior(trainingData.toIndexedSeq) | |
show(posterior, "posterior") | |
val modelLMs = LandmarkIO.readLandmarksJson[_3D](new File("datasets/modelLandmarks.json")).get | |
addLandmarksTo( modelLMs, "model") | |
val noselessLMs = LandmarkIO.readLandmarksJson[_3D](new File("datasets/noselessLandmarks.json")).get | |
addLandmarksTo( noselessLMs, "noseless") | |
val modelLandmarks = getLandmarksOf("model").get | |
val noselessLandmarks = getLandmarksOf("noseless").get | |
val trainingData = (modelLandmarks zip noselessLandmarks).map{ case (mLm, nLm) => | |
(model.mean.findClosestPoint(mLm.point).id, nLm.point, littleNoise) | |
} | |
val betterPosterior = model.posterior(trainingData.toIndexedSeq) | |
show(betterPosterior, "betterPosterior") | |
val nosePtIDs = model.referenceMesh.pointIds.filter { id => | |
(model.referenceMesh.point(id) - model.referenceMesh.point(PointId(8152))).norm <= 42 | |
} | |
val posteriorNoseModel = betterPosterior.marginal(nosePtIDs.toIndexedSeq) | |
show(posteriorNoseModel, "posteriorNoseModel") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment