SimpleITK保存.nii.gz的文件

            print('img_path', img_path[0])
            img_img = load_itk(img_path[0])   # 正常读取,sitk.ReadImage(path)

            # img_img = nibabel.load(img_path[0]).get_data()
            img_array = sitk.GetArrayFromImage(img_img)  # [channel, height, width,]
            img_array_copy = sitk.GetArrayFromImage(img_img)
            channel, height, width = img_array.shape  # [channel, h, w]
            for j in range(channel):
                image = img_array[j]
                image = cv2.resize(image, (480, 480))  # resize成网络训练的h*w
       
                image_x = image
                image_x = np.expand_dims(image_x, axis=-1)
                image_x = np.expand_dims(image_x, axis=0)   # 这两个是添加成[b, h ,w ,c]的维度
                feed_dict = {
                    image_placeholder:image_x,
                    training_flag:False,
                }
                result, idx_map = sess.run([logits, seg_image], feed_dict=feed_dict)
				# idx_map是输出的预测图[1, h, w] --上面为分类好的类别
                print('idx_map.shape', np.unique(idx_map))
                # [0 1 2 3] *200
                output = idx_map * 200                          ######## 这下面就是*像素
                # print('outouyt.un', np.unique(output))
                output_copy = output.copy()
                # 将400 - 》 500
                # print('outpyt_copy', np.unique(output_copy))
                output[output_copy == 400] = 500
                # 消除最后一维度
                # 变回原来的大小
                output = np.squeeze(output).astype(np.float32)
                output = cv2.resize(output, (height, width))        ###### 将其resize成 图像的原题大小
                output = np.expand_dims(output, axis=0)
                # 装数据
                img_array_copy[j, :, :] = output[0, :, :]  ### 将其放在第j个切片上
                ax[0, 1].imshow(image_x[0,:,:,0])       ###### 这是plt.show()
                ax[1, 1].imshow(output[0, :, :]) 
                plt.show()
                plt.pause(0.5)
            # 数据保存为nii格式
            last_ouput = sitk.GetImageFromArray(img_array_copy)  # 将array转成image
            last_ouput.CopyInformation(img_img)  # 将读取数据的信息copy给结果的数据
            sitk.WriteImage(last_ouput, 'F:\image\competition\mysvaeee/patient'+str(i)+'.nii.gz') #保存为nii.gz 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值