Rigid Alignment in Scalismo

97 views
Skip to first unread message

Debbie Lam

unread,
Mar 4, 2022, 6:41:56 AM3/4/22
to scalismo
Hi,

I'm currently working on a personal project of building a statistical skull model. I've been using ScalismoLab, but it wasn't able to handle the procedures (it will hang when carrying out rigid alignment). Therefore, I'm trying to do it in Scalismo. However, the coding syntax is quite different. I've tried several times to execute landmarking and rigid alignment but it failed with a landmarking error (see Pic 1). May I know what is the problem with my code?

object HelloScalismo extends App {

  scalismo.initialize()
  implicit val rng = scalismo.utils.Random(42)

  val ui = ScalismoUI()
  import scalismo.io.MeshIO

  //Import skull meshes
  val meshFiles = new java.io.File("skulls/").listFiles.take(5)
  val dataset = meshFiles.map{ f => MeshIO.readMesh(f).get}
  val mesh: TriangleMesh[_3D] = dataset(0)
  val meshView = ui.show(mesh, "reference")
  meshView.color = java.awt.Color.RED
  (1 until 5).foreach{i :Int => ui.show(dataset(i), "skull_"+i)}

  //After landmarking (4 points each), carry out rigid alignment
  import scalismo.registration.LandmarkRegistration
  import scalismo.io.LandmarkIO
//   val Lms : IndexedSeq[Landmark[_3D]] = LandmarkIO.readLandmarksJson3D(new java.io.File("landmarks/")).get.toIndexedSeq
//   println(Lms)
  val reference_Lms = LandmarkIO.getLandmarksOf("reference").get
  val skull_1_Lms =  LandmarkIO.getLandmarksOf("skull_1").get
  val bestTransform : RigidTransformation[_3D] = LandmarkRegistration.rigid3DLandmarkRegistration(
    reference_Lms,
    skull_1_Lms,
    center = Point(0, 0, 0)
)

  val aligned_skull_1 = mesh.transform(bestTransform)
  val alignedPaola = mesh.transform(bestTransform)
  val alignedView = ui.show(aligned_skull_1, "aligned_skull_1")
  alignedView.color = java.awt.Color.BLUE
 
}
Pic 1.jpg

Marcel Luethi

unread,
Mar 7, 2022, 3:00:19 AM3/7/22
to scalismo
Hi

As you noticed, quite some methods have changed compared to ScalismoLab. Instead of starting with the code from ScalismoLab, it is therefore easier to start with the code from the corresponding scalismo tutorial. For rigid alignment this is Tutorial 2. https://scalismo.org/docs/Tutorials/tutorial02. There is also a download link for the corresponding tutorial code.
In general, every Tutorial in ScalismoLab has a corresponding tutorial that shows how the code looks in "modern" Scalismo. You can find an overview of all the tutorials on https://scalismo.org/docs.

Best regards,

Marcel

Debbie Lam

unread,
Mar 7, 2022, 8:26:21 AM3/7/22
to scalismo
Hi, Marcel.

I've studied Scalismo Tutorial 2 and rewrote my code. I plan to import predefined landmarks and execute rigid alignment. However, currently, rigid alignment couldn't be executed due to an error (see attachment: pic 1). It stated that: Empty set of landmarks provided. According to the attached pic 2, my landmarks had been successfully imported and displayed.

May I know what is the issue with my code?

Thank you!
pic 2.jpg
pic 1.jpg
Reply all
Reply to author
Forward
0 new messages