junqiangchen / LiTS---Liver-Tumor-Segmentation-Challenge

LiTS - Liver Tumor Segmentation Challenge
MIT License
234 stars 73 forks source link

请问在准备数据时,怎样处理可以直接将裁剪的数据保存为nii格式而不是多张.bmp图片? #14

Closed li-pengcheng closed 5 years ago

li-pengcheng commented 5 years ago

请教一下,在函数gen_image_mask中,您保存的是16张256×256的图片,我是否可以将这16幅图保存为一个nii文件呢?具体应该怎么操作?谢谢

li-pengcheng commented 5 years ago

我做了如下修改,结果奏效了:)

for z in range(imagez):

        #     image = sub_srcimages[j, z, :, :]
        #     image = image.astype(np.float32)
        #     image = np.clip(image, 0, 255).astype('uint8')
        #     cv2.imwrite(filepath + str(z) + ".bmp", image)
        #     cv2.imwrite(filepath2 + str(z) + ".bmp", sub_masks[j, z, :, :])
        image = sub_srcimages[j, :, :, :]
        image = sitk.GetImageFromArray(image)
        mask = sub_masks[j,:,:,:]
        mask = sitk.GetImageFromArray(mask)
        sitk.WriteImage(image, filepath + 'img_patch.nii')
        sitk.WriteImage(mask, filepath2 + 'gt_patch.nii')