파이썬

dicom to nifti에서 발생하는 오류 - TypeError: float() argument must be a string or a number, not 'NoneType'

밀루루 2022. 5. 1. 20:45

왜.. 안되지..? 왜 안되냐고! 다른 폴더는 실행하면서 왜 label 폴더만 실행 안되는 거냐고! ㅠㅠ

 

Solution !

dicom 파일의 RepetitionTime과 EchoTime을 0(False)로 바꾼 후 다시 저장해 nii.gz로 변환하면 된다!

아래는 관련 코드.. glob 쓰려고 했는데 attribute error가 떠서 os.listdir을 사용했다

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def change_to_nii(dcm_path, nii_path):
 
    settings.disable_validate_orthogonal()
    settings.enable_resampling()
    settings.set_resample_spline_interpolation_order(1)
    settings.set_resample_padding(-1000)
 
    #files = sorted([path for path in glob.glob(dcm_path+'/*')])
    files=sorted(os.listdir(dcm_path))
    
    for dicom_file in files:
        #print(dicom_file)
        dicom_f=dcm_path+'/'+dicom_file
        # noinspection PyBroadException
        dicom = pydicom.dcmread(dicom_f)
        dicom.EchoTime = False
        dicom.RepetitionTime = False
        dicom.save_as(dicom_f)
 
 
    dicom2nifti.convert_directory(dcm_path, nii_path)
    
change_to_nii(input_path, out_path)
cs

 

석사 선배님.. 감사합니다.. (이거로 삽질하다가 데이터셋도 날려먹은 나..)