opencv & plt可视化显示nii中的slice

Extracting data:

1.nibable

import nibabel as nib
nii_1 = nib.load(img1_path)
nii_1 = nii_1.dataobj #obtain the nii data
nii_2 = nib.load(img2_path)
nii_2 = nii_2.dataobj #obtain the nii data

2.SimpleITK(additional method for dicom)

import SimpleITK as sitk
reader = sitk.ImageSeriesReader()
img_names = reader.GetGDCMSeriesFileNames('imgfolder')
reader.SetFileNames(img_names)
image = reader.Execute()
image_array = sitk.GetArrayFromImage(image) 

使用opencv显示nii_1和nii_2中的slice

def nothing(emp):
    pass

def visualize(name,frames):
    cv2.namedWindow(name,0)
    #cv2.resizeWindow(name, 800, 600)
    loop_flag = 0
    pos = 0
    cv2.createTrackbar('time', name, 0, frames, nothing)
    while True:
        if cv2.waitKey(1) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
        pos = cv2.getTrackbarPos('time', name)
        img1_new = nii_1[pos]
        img2_new = nii_2[pos]
        img_new = np.hstack([img1_new,img2_new])
        cv2.imshow(name, img_new)

visualize('img', len(high_data)-1)

使用plt显示nii_1和nii_2中的slice

 for i in range(len(low_data)):
     fig = plt.figure()
     fig.add_subplot(1,2,1)
     plt.imshow(low_data[i],cmap='gray')
     fig.add_subplot(1,2,2)
     plt.imshow(high_data[i],cmap='gray')
     plt.pause(1)
     plt.close()

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值