pythonimagemetadataimagejqupath

How to edit metadata from .svs Aperio whole slide image?


I have whole slide images, in .svs format, that have be digitized with Leica aperio scan. Thanks to openslide package (https://openslide.org/), I figured out that those .svs files contain a lot of metadata, especially the 'Filename' that can contain patient-related information. I would like to anonymize completely those metadata, but after several days, I haven't been able to find a way to do so.

I tried :

So, I would like to know if it is possible to edit .svs metadata with openslide ? Or any other python package ? Or another third party software (Qupath, imageJ...) ? Please, could you let me know if you already had this issue ? And if you have any lead in order to adress this question ?


Solution

  • Someone from forum.image.sc gave me the answer to my issue (1) :

    """
    Created on Fri Dec  2 12:28:03 2022
    
    @author: zalavadia.ajay@gmail.com
    """
    import tifffile
    
    def replace_filename(svs_path,new_name):
        fp = open(svs_path, 'r+b')
        t = tifffile.TiffFile(fp)
        org_description = t.pages[0].description
        str1 = org_description.split("|Filename = ",1)
        f_name = str1[1].split("|",1)
        print('file name found: ' + f_name[0])
        t.pages[0].tags['ImageDescription'].overwrite(t.pages[0].description.replace(f_name[0],new_name))
        t.pages[1].tags['ImageDescription'].overwrite(t.pages[1].description.replace(f_name[0],new_name))
        fp.close()
    

    replace_filename('CMU-1.svs','de-identified name')

    Kindly yours