Convert hdf5 to raw organised in folders

后端 未结 1 1927
无人共我
无人共我 2021-01-27 05:52

I use a script to make images match with an atlas. This script input is .raw images organised in folders like:

imageFolder
-- folder1
---- image1.r         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 06:34

    Feiten, you can use .visititems() to recursively call a function (def) to export the data. You can query the object type and name. Group names will be your folder names and Dataset names will be your file names. Attached is a very simple example that shows how to use .visititems(). It has some print statements (commented out) that output more info if you are unfamiliar with h5py and/or HDF5 structure. This should get you started.

    import h5py
    
    def print_grp_name(grp_name, object):
    
    #  print ('object = ' , object)
    #  print ('Group =', object.name)
    
      try:
        n_subgroups = len(object.keys())
        #print ('Object is a Group')
      except:
        n_subgroups = 0
        #print ('Object is a Dataset')
        dataset_list.append (object.name)
    
    #  print ('# of subgroups = ', n_subgroups )
    
    if __name__ ==  '__main__' :  
        with h5py.File(your-filename-here,'r') as h5f:
    
            print ('visting group = ', h5f)
            dataset_list = []
            h5f.visititems(print_grp_name)
    
        print (dataset_list)    
    

    0 讨论(0)
提交回复
热议问题