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()

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章