2021-07-18 三种视图的dicom文件的生成
生活随笔
收集整理的這篇文章主要介紹了
2021-07-18 三种视图的dicom文件的生成
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
根據(jù)截?cái)嗝娴膁icom文件生成三種視圖的dicom文件
由于給出的dicom文件只有階段面的展示,而我們需要完成橫斷面、矢狀面、冠狀面三種視圖的展示。在js方面缺少對dicom文件進(jìn)行處理的庫,因此需要借助python 的SimpleITK庫來生成三種視圖的dicom文件,以此來在前端網(wǎng)頁進(jìn)行展示。
網(wǎng)上教程質(zhì)量都比較低下,為此花費(fèi)一些時間查看了SimpleITK的官方文檔和例子,完成了三種視圖的dicom文件的生成。
以下是python代碼:
import SimpleITK as sitk import os# 輸出某一切片dicom文件 # new_img是三維數(shù)據(jù) # out_dir是輸出到的文件夾 def writeSlices(new_img, targetPath):if os.path.exists(os.path.join(targetPath, 'hengduanmian')) == False:os.mkdir(os.path.join(targetPath, 'hengduanmian'))if os.path.exists(os.path.join(targetPath, 'shizhuangmian')) == False:os.mkdir(os.path.join(targetPath, 'shizhuangmian'))if os.path.exists(os.path.join(targetPath, 'guanzhuangmian')) == False:os.mkdir(os.path.join(targetPath, 'guanzhuangmian'))shape = new_img.GetSize()for i in range(shape[2]):image_slice = new_img[:, :, i]sitk.WriteImage(image_slice, os.path.join(os.path.join(targetPath, 'hengduanmian', str(i) + '.dcm')))for i in range(shape[1]):image_slice = new_img[:, i, :]sitk.WriteImage(image_slice, os.path.join(os.path.join(targetPath, 'guanzhuangmian', str(i) + '.dcm')))for i in range(shape[0]):image_slice = new_img[i, :, :]sitk.WriteImage(image_slice, os.path.join(os.path.join(targetPath, 'shizhuangmian', str(i) + '.dcm')))if __name__ =='__main__':dicomsPath = './CBCT'targetPath = './dcmOutPut'reader = sitk.ImageSeriesReader()dicom_names = reader.GetGDCMSeriesFileNames(dicomsPath)reader.SetFileNames(dicom_names)image = reader.Execute()writeSlices(image, targetPath)總結(jié)
以上是生活随笔為你收集整理的2021-07-18 三种视图的dicom文件的生成的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c#制作图表(从数据库读取数据,制作柱状
- 下一篇: iOS UITableview 禁止上下