Thanks very much for your assistance so far. I've spent the weekend attempting to get the model up and running, and was actually successful! However, the model didn't perform as well as anticipated and looking back at some of the meshes I think my registration needs improving as the quality of the meshes from pre-to-post registration really decreases. I've attached a couple of images (see below) so that you can see an example of a mesh before and after. I've added the code i'm using for registration below too. I've tried varying iterations, number of points, random vs. uniform mesh sampler, as well as a couple of different registration methods. No luck. Is there a way to register each mesh and not lose quality??
Thanks again for the help so far. I'm hoping i'm really close to getting the hang of things?!
// load deformation model // use code above to produce deformation model if not already produced
val shapeModel = StatismoIO.readStatismoMeshModel(new File("datasets/Ft/Def_mod/Model_Unldd_aligned.h5")).get
show(shapeModel, "Model")
// load reference mesh to enable goodness of fit assessment
val referenceMesh = MeshIO.readMesh(new File("datasets/Ft/Unldd_aligned/0.CP.stl")).get
show(referenceMesh, "referenceMesh")
// load target mesh
val targetMesh = MeshIO.readMesh(new File("datasets/Ft/Unldd_aligned/2.EB.stl")).get
show(targetMesh, "targetMesh")
val evaluationSampler = UniformMeshSampler3D(
referenceMesh,
numberOfPoints = 500,
seed = 42
)
val regConfig = RegistrationConfiguration(
optimizer = GradientDescentOptimizer(numIterations = 50, stepLength = 0.1),
metric = MeanSquaresMetric(evaluationSampler),
transformationSpace = GaussianProcessTransformationSpace(lowRankGP),
regularizationWeight = 1e-8,
regularizer = L2Regularizer
)
val fixedImage = Mesh.meshToDistanceImage(referenceMesh)
val movingImage = Mesh.meshToDistanceImage(targetMesh)
val regIterator = Registration.iterations(regConfig)(fixedImage, movingImage)
val resultIterator = for ((it, itnum) <- regIterator.zipWithIndex) yield {
println(s"object value in iteration $itnum is ${it.optimizerState.value}")
setCoefficientsOf("Model", it.registrationResult.parameters)
it.registrationResult
}
val registrationTransform = resultIterator.toSeq.last
val projection = (pt : Point[_3D]) => {
val targetPt = targetMesh.findClosestPoint(pt).point
targetPt
}
val finalTransform = registrationTransform.andThen(projection)
val regResult = referenceMesh.transform(finalTransform)
show(regResult, "projection")