jvwilliams23 / pyssam

A Python library for biomedical statistical shape and appearance modelling.
https://pyssam.readthedocs.io/
GNU Affero General Public License v3.0
30 stars 2 forks source link

Code for landmarking the dataset (automatic algorithm detailed by [Ferrarini et al. (2007)]) #8

Closed larajk closed 7 months ago

larajk commented 9 months ago

Hello Josh,

I'm currently working on my Bachelor's Thesis. It's about statistical shape modeling using the example of femoral heads. I segmented my CT-scans and now have a 3D model of each femoral head. I could not find any code, to automatically set landmarks on my segmentation. I tried using your code by having the segmentations as STL-data and using those already existing landmarks. That obviously did not make sense because my data is not oriented and I don't think it would work either way. You mentioned that you used an automatic algorithm detailed by [Ferrarini et al. (2007)]. Is it possible to share this code?

Thanks for your help.

Best wishes,

Lara

jvwilliams23 commented 9 months ago

Hi Lara,

Thanks for using pyssam!

I have a rough version of this code on the landmarking branch (https://github.com/jvwilliams23/pyssam/blob/landmarking/scripts/games_landmarking.py). I had problems in verifying it on very simple cases such as a torus, and have not had any time to give it another try, so it may need some modification. It would serve as a good starting point for you though.

There is also a manual landmarking tool on the main branch here. If you do not make much progress on the Ferrarini algorithm, this one could be a useful backup.

Best, Josh

larajk commented 9 months ago

Hi Josh,

Thank you for your fast reply and sharing your code. I appreciate it.

Best, Lara

larajk commented 9 months ago

Hello Josh,

if I understand correctly every dataset needs to be the same length for the SSM code to work for example. How do you ensure that every dataset has the same length? Do you shorten every dataset after you created a new dataset through landmarking? My thought is to take the shortest dataset after landmarking and shorten every other dataset to that length by deleting every x. line. I'm not sure if the SSM code would work properly with that approach.

Thanks for your help.

Best, Lara

jvwilliams23 commented 9 months ago

Hi Lara,

Each sample in your dataset should have the same number of points (or more generally, 'features'), yes. Feature 0 in sample 0 must represent the same physical information as feature 0 in sample 1. This is called correspondence.

The method you describe of shortening the dataset seems like you are referring to the STL vertex coordinates, which are not ordered and have no knowledge of the other STLs in your dataset. Sometimes, people use the "shortest" list of STL coordinates and register these to all other meshes using iterative closest points (ICP), but there is no guarantee this represents the same feature so it is likely to produce incorrect results.

In the Ferrarini paper, they first create a baseline set of landmarks (they call this the growing phase). This is then morphed to a new dataset (because we are just morphing/transforming the landmarks we already had to a new sample, they are the same size).

Hope that helps.

Short answer; do not use STL coordinates as SSM inputs! 😄

Josh

jvwilliams23 commented 9 months ago

Please see section 4.1 of the following paper:

Heimann, T. and Meinzer, H.P., 2009. Statistical shape models for 3D medical image segmentation: a review. Medical image analysis, 13(4), pp.543-563.

larajk commented 8 months ago

Hello Josh,

Thanks for your reply. I missed something in your code. After minor changes in my additions in your code it worked and with your landmarking code I ended up with datasets of same length.

Best, Lara

jvwilliams23 commented 8 months ago

And does the SSM result seem realistic?

Did you need to make any modifications to the landmarking code?

jvwilliams23 commented 7 months ago

If there is nothing else, I will close this in 1 week due to inactivity. @larajk

larajk commented 7 months ago

Hello Josh,

Sorry for not answering your message. I had some problems because the ssm result did not seem realistic at all. I was not sure if it was because of the code or my stl data. Now I'm quite sure the problem was the data. I did some small tests with the changed stl data and those ssm results are promissing. I made no changes to your ssm code or your landmarking code. I just changed ssm plot from 2D to 3D.

Thank you for all your help!

Best, Lara

jvwilliams23 commented 7 months ago

No worries. I will close this issue. If any other questions, feel free to raise an issue or discussion.

Best, Josh