Model Fitting using MCMC

82 views
Skip to first unread message

Federica Damonte

unread,
Dec 4, 2019, 4:18:05 AM12/4/19
to scalismo
Hello!
I'm trying to implement the MCMC method to fit a shape with my model , but the problem is that I do not have landmarks so I thought to randomly sample but the output is not compatible with the rest of the code...is there another way? can you help me with this? I'm currently using the code showed in the tutorial https://scalismo.org/tutorials/tutorial15.html .. best regards


Here the code:
val targetMesh = MeshIO.readMesh(new java.io.File("C:/Users/User/Desktop/patella/bone/DU04_Pat_Bone.stl")).get
val targetGroup = ui.createGroup("target")
ui.show(targetGroup, targetMesh, "cartilageless")

//loading the model
val model = StatisticalModelIO.readStatisticalMeshModel(new java.io.File("C:/Users/User/Desktop/patella/modelbone.h5")).get
val modelGroup = ui.createGroup("bone model")
val modelView = ui.show(modelGroup, model, "bone model")
modelView.meshView.opacity = 0.5

val modelLmIds = (0 until model.mean.pointSet.numberOfPoints by 20).map(i => PointId(i))
def attributeCorrespondences(movingMesh: TriangleMesh[_3D], ptIds : Seq[PointId]) : Seq[(Point[_3D], Point[_3D])] = {
ptIds.map{ id : PointId =>
val pt = movingMesh.pointSet.point(id)
val closestPointOnMesh2 = model.mean.pointSet.findClosestPoint(pt).point
(pt, closestPointOnMesh2)
}
}
val targetPoints= attributeCorrespondences(targetMesh, modelLmIds)

Andreas Forster

unread,
Dec 4, 2019, 8:05:06 AM12/4/19
to Federica Damonte, scalismo
Hi Federica,

A good starting point for a fitting with MCMC could be the following snippet. Of course the proposals and evaluators which are the most interesting parts, i left out. The proposals should not change much depending on which information you have, landmarks or not. But you will need an adapted evaluator.

I do not get your point of sampling points when you do not have landmarks. Landmarks are an instance of the concept of point-to-point correspondence and are therefore very well defined on the model and the target. Just random sampling would not give you point pairs in correspondence. Or did I understand you wrong? Is it impossible to define landmarks?

If you have well-aligned shapes you could maybe directly start with a likelihood similar to the average shape distance. Then you would not need landmarks. If they are not well aligned, consider first to adapt only the pose, so only use pose proposals first. Then when you have well-aligned shapes, you could mix shape and pose proposals for a second step where you then calculate the shape fitting as non-rigid registration. For both phases, you could use the same evaluator based on average shape distance.

I hope this gives you additional input on how to approach the fitting with MCMC.

Best, Andreas


object MCMCFitting extends App {

case class FitParameter(translationParameters: EuclideanVector[_3D],
pitchRotation: Double,
yawRotation: Double,
rollRotation: Double,
modelCoefficients: DenseVector[Double],
center: Point[_3D])
scalismo.initialize()
implicit val rng = Random(1024l)

val init: FitParameter = ???
val ssm: StatisticalMeshModel = ???
val target: TriangleMesh[_3D] = ???

val proposal: ProposalGenerator[FitParameter] with TransitionProbability[FitParameter] = ???
val evaluator: DistributionEvaluator[FitParameter] = ???

val chain = MetropolisHastings(proposal,evaluator)
val sampleIterator = chain.iterator(init)
val samples = sampleIterator.take(1000).toIndexedSeq
val maximumAPosterioriSample = samples.maxBy( s => evaluator.logValue(s))

val finalRigidTransformation = RigidTransformation(
TranslationTransform(maximumAPosterioriSample.translationParameters),
RotationTransform(
maximumAPosterioriSample.pitchRotation,maximumAPosterioriSample.yawRotation,maximumAPosterioriSample.rollRotation,
maximumAPosterioriSample.center)
)
val finalShape = ssm.instance(maximumAPosterioriSample.modelCoefficients).transform(finalRigidTransformation)

}


--
You received this message because you are subscribed to the Google Groups "scalismo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalismo+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalismo/4a539f15-f12f-4090-9e31-2f94e4737f9a%40googlegroups.com.


--
*****************************************
Dr. Andreas Morel-Forster
Departement Mathematik und Informatik
Spiegelgasse 1
CH-4051 Basel
PHONE: +41 61 207 05 52
MAIL: Andreas.Forster@unibas.ch
*****************************************
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages