fphammerle / freesurfer-surface

Python Library to Read and Write Surface Files in Freesurfer's TriangularSurface Format
https://pypi.org/project/freesurfer-surface/
GNU General Public License v3.0
8 stars 0 forks source link

Put the updated vertex_label into .annotation #30

Open tanjia123456 opened 3 years ago

tanjia123456 commented 3 years ago

hello, After I updated the vertex_label of rh.aparc.a2009s.annot with an algorithm, now I want to replace the vertex_label in the .annot with the updated vertex_label, mainly to see the effect of the segmentation, do you know what to do ?

The procedure for extracting vertex_index, vertex_label is as follows:

from freesurfer_surface import Surface
from freesurfer_surface import Label
from freesurfer_surface import Annotation

surface = Surface.read_triangular('rh.white')
surface.load_annotation_file('rh.aparc.a2009s.annot')
with open("rhlabels1.txt","w") as f:
    for vertex_index, vertex in enumerate(surface.vertices):
        vertex_label_index = surface.annotation.vertex_label_index[vertex_index]
        vertex_label = surface.annotation.labels[vertex_label_index]
        #print(vertex_index, vertex, vertex_label)
        #f.write("vertex_index:{}  vertexlabel:{} \n".format(vertex_index, vertex_label))
        f.write("vertex_index:{} vertex_label:{}\n".format(vertex_index, vertex_label))
fphammerle commented 3 years ago

Hi,

sorry, this library does not yet support creating / writing annotation files

Basically you need to invert this reader function: https://github.com/fphammerle/freesurfer-surface/blob/1.1.0/freesurfer_surface/__init__.py#L267

tanjia123456 commented 3 years ago

OK, I will have a try. Thank you very much!

tanjia123456 commented 3 years ago

@fphammerle https://rdrr.io/cran/freesurferformats/man/write.fs.annot.html This may be useful, if you know how to write it, please open source the code, thank you!