GUDHI / TDA-tutorial

A set of jupyter notebooks for the practice of TDA with the python Gudhi library together with popular machine learning and data sciences libraries.
MIT License
378 stars 114 forks source link

About gudhi library application to brain surface segmentation #42

Open tanjia123456 opened 3 years ago

tanjia123456 commented 3 years ago

Hello, thank you for your works. I want to use ph to extract topological features and perform a post-processing on the surface segmentation of the cerebral cortex. But I am currently a little confused as to whether I can apply ph to my subject. I see that the Tuto-GUDHI-extended-persistence.py file processes 3D data. For the brain, I also obtained the 3D trisurf based on the three-dimensional coordinate points (coord) and the triangle connection relationship (triangle). For this structure of the brain, should I use persistence barcode or extended persistence barcode? Or something else lasts? Or do you have any suggestions for me?

tanjia123456 commented 3 years ago

Three-dimensional map of cerebral cortex:https://github.com/tanjia123456/Brain/blob/main/brain_graph.png

mglisse commented 3 years ago

This is a common difficulty with TDA, you don't just throw it at your data, you need to select some view of your data, here a filtration. You could compute the homology (not persistent) of your surface, but it would likely not be very informative, probably it is just a sphere. You could filter by one coordinate as in the tutorial you mention (or by a function like the curvature), I don't know how informative that would be for your data. You could also consider the filtration of the offsets of your surface. We don't directly provide that, but since the triangles are rather small (and you can always subdivide if they are not small enough), computing the offsets of the vertices (with AlphaComplex) should give a similar result with extra points close to the diagonal. And there are certainly a number of other filtrations one could think of. If you were inspired by some paper using persistent homology on brain data, you may want to check in more details what filtration they were using.

Extended persistence can apply when you are filtering your surface by a function, not so much for offsets or other filtrations. In some sense it allows you to get the result for a function f and -f at the same time, plus some information about the unfiltered space (not relevant here).

tanjia123456 commented 3 years ago

Hello, thank you for your reply. My current data set not only has vertices and triangles, but also some characteristic files of the cerebral cortex, such as curvature, cortical thickness, and sulcus depth. You mean to use a certain characteristic (choose a threshold) as a filter condition to filter. So how to calculate the betti number next? Are there any relevant steps in your code as a reference? I just came into contact with TDA, so I don't really understand it yet.

mglisse commented 3 years ago

You mean to use a certain characteristic (choose a threshold) as a filter condition to filter

Only if that makes sense for your data. Persistence is about looking at the evolution of the topology (connected components, cycles) of a sequence of objects. One easy way to define a sequence could be using curvature as a parameter, so you start from the regions of low curvature, progressively include regions of higher and higher curvature, until you have the whole surface, and you can see how components and cycles appeared and merged during this growth (you could instead look at minus the curvature, so it starts from high curvature regions, or use extended persistence to get both, or use another one of your characteristics). That may or may not be something of interest to you, it is easy to define meaningless filtrations and harder to come up with some that are relevant to a particular application.

You say you want to "use ph to extract topological features and perform a post-processing on the surface segmentation", but that's not very precise. I don't see any segmentation on your image. Sometimes reconstruction algorithms "fail" and reconstruct a surface with strange artifacts (long thin triangles that connect regions that are close but should not be connected) and people talk about topological errors, is that what you are talking about? (the picture doesn't look like it has such errors).

So how to calculate the betti number next?

Usually we don't just compute Betti numbers (that would be taking one value of the parameter), we compute the whole persistence diagram (the evolution when the parameter changes), although that certainly also gives you Betti numbers.

Are there any relevant steps in your code as a reference?

Almost all our examples compute persistence somewhere...

I just came into contact with TDA, so I don't really understand it yet.

https://arxiv.org/abs/1710.04019 can be a nice introduction.

tanjia123456 commented 3 years ago

Ok, than you very much. I want to show you what I have get: https://github.com/tanjia123456/Brain/blob/main/Ground%20truth.png https://github.com/tanjia123456/Brain/blob/main/after%20process.png

My results are not good, I will assign a wrong label to a node. So I wonder if the introduction of PH can alleviate such problems? I have found some articles introduce TopoLoss to improve performance and get better results.

tanjia123456 commented 3 years ago

Hello, sorry to bother you again. Q1: I have use brain cortical curv of each vertex as filteration value, but when i use the following code: for i in range(len(data_vertices)): st.assign_filtration([i], filtration = filteration_value[i])

st.assign_filtration([0], filtration = filteration_value[0])#success!

 #st.assign_filtration([0], filtration = filteration_value[i])#success!
 error:Process finished with exit code -1073741819 (0xC0000005)
 I have tried some solution, but it's doesn't work! I'm curious why filter values can only be fed one node at a time.

Q2: I add filter value manually st.assign_filtration([0], filtration = filteration_value[0]) st.assign_filtration([1], filtration = filteration_value[1]) st.assign_filtration([2], filtration = filteration_value[2]) st.assign_filtration([3], filtration = filteration_value[3])

But you said use extended_persistence, I have use it, but : st2 = gd.SimplexTree() st2.extend_filtration() dgms2 = st2.extended_persistence(min_persistence=1e-5) gd.plot_persistence_barcode(dgms2)#IndexError: list index out of range plt.show() the error message:
IndexError: list index out of range but when I use gd.plot_persistence_barcode(dgm),use ordinary persistent barcode, there's no problem. What code should I use to get the extended continuous bar code directly?

Q3: I've added filter values to each node. What pair of distances do I need to use to weight the edges?

Q4: Afetr I get the extended_persistent_barcode, How to get betti???

My datasets and codes are in:https://github.com/tanjia123456/Brain_area_PH/blob/main/compute_betti_gudhi3.py

tanjia123456 commented 3 years ago

@mglisse