catactg / lasc

Left Atrial Segmentation Challenge 2013
BSD 2-Clause "Simplified" License
22 stars 7 forks source link

Have you any suggestions : if I want to evaluate my segmentation but I have my image results as PNG ! what changes should be make to the original script!!! #6

Open sebyo opened 4 years ago

catactg commented 4 years ago

Hi sebyo: I suggest you convert your PNG files to mhd format. You can do it using SimpleITK like this:

  1. load each PNG file using sitk.ImageFileReader() and append each file to a list

    image_list = []


    for filename in filename_list:
    
     fullpath = os.path.join(input_dir, filename)
    
     reader = sitk.ImageFileReader()
    
     reader.SetImageIO('PNGImageIO')
    
     reader.SetFileName(fullpath)
    
     image = reader.Execute()
    
     image_list.append(image)
  2. convert the list to a 3d numpy array (note that the coordinate standard for numpy is [z,y,x] while for itk is [x,y,z]

    slices_size = np.shape(sitk.GetArrayFromImage(itkimages[0]))

    number_of_slices = len(itkimages)

    npa = np.zeros((number_of_slices, slices_size[0], slices_size[1]))


    for slice_index, image in enumerate(itkimages):
   
    # only keep one channel (expected that greyscale image has identical channels)
    
    if image.GetNumberOfComponentsPerPixel() > 1:
        
        npa[slice_index, :, :] = sitk.GetArrayFromImage(image)[:, :, 0]
    
    else:
        
        npa[slice_index, :, :] = sitk.GetArrayFromImage(image)

    itk_image_stack = sitk.GetImageFromArray(npa)
  3. save it as mhd using sitk.WriteImage()

    outpath = os.path.join(output_dir, your_filename + '.mhd')
   
    sitk.WriteImage(itk_image_stack, outpath)