for root, dirs, files in os.walk(input_folder):
for file in files:
if file.endswith('.nii.gz'):
img_path = os.path.join(root, file)
mask_path = img_path.replace('img.nii.gz', 'mask.nii.gz') # 根据实际掩膜文件命名修改
if os.path.exists(mask_path):
image = sitk.ReadImage(img_path)
mask = sitk.ReadImage(mask_path)
input_image = sitk.Cast(image, sitk.sitkFloat32)
input_mask = sitk.Cast(mask, sitk.sitkUInt8)
corrector = sitk.N4BiasFieldCorrectionImageFilter()
加个遍历不就行啦