当前位置:网站首页>Read MHD and raw images, slice, normalize and save them
Read MHD and raw images, slice, normalize and save them
2022-06-12 16:12:00 【friedrichor】
Statement

Make suggestions normally , I accept . I advise you not to look at it , If you don't like it, don't look , Cheap or not .
Preface
raw What is stored is a 3D Of CT image ,mhd The file stores the corresponding raw File information
My dataset train/low dose The contents of the folder are as follows ,mhd and raw Under the same folder :
Read mhd、raw And slice
Use SimpleITK library mhd and raw File reading
import os
from tqdm import tqdm
import SimpleITK as sitk
import matplotlib.pyplot as plt
def slice(ori_path: str, pro_path: str):
for path in os.listdir(ori_path):
if path.find('mhd') >= 0:
data_mhd = sitk.ReadImage(os.path.join(ori_path, path))
spacing = data_mhd.GetSpacing()
scan = sitk.GetArrayFromImage(data_mhd)
for i in tqdm(range(len(scan))):
plt.figure()
plt.imshow(scan[i], cmap=plt.cm.bone)
plt.show()
break # Here is just a demonstration of the effect after slicing , So use the break, Normal traversal will be deleted directly break Just go
call :
low_dose_path = 'train/low dose' # Original dataset path
low_dose_slice_path = 'train_slice/low_dose_slice' # Save the path
slice(low_dose_path, low_dose_slice_path)
Picture demonstration example :
section 、 normalization 、 preservation
def slice(ori_path: str, pro_path: str):
id = 0
for path in os.listdir(ori_path):
if path.find('mhd') >= 0:
id += 1
save_content = os.path.join(pro_path, str(id))
if os.path.exists(save_content):
shutil.rmtree(save_content)
os.makedirs(save_content)
data_mhd = sitk.ReadImage(os.path.join(ori_path, path))
spacing = data_mhd.GetSpacing()
scan = sitk.GetArrayFromImage(data_mhd)
for i in tqdm(range(len(scan))):
img = cv2.normalize(scan[i], None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
img = Image.fromarray(img)
save_path = os.path.join(save_content, f'{
id}_{
i}.png')
img.save(save_path)
explain :
My dataset 3D The pixel value of the image is -3000 To 3000 many , And our normal images are 0-255 Of , So the best way is to use cv2.normalize Normalize to 0-255 Between , And then save .
If you write a normalized code by yourself , Or use from sklearn.preprocessing import minmax_scale This minmax_scale function , There will be some strange problems , I guess it may be that the loss of normalization is very large , So there will be some problems .
Call as above :
low_dose_path = 'train/low dose' # Original dataset path
low_dose_slice_path = 'train_slice/low_dose_slice' # Save the path
slice(low_dose_path, low_dose_slice_path)
Preservation effect :


边栏推荐
- Project training of Software College of Shandong University rendering engine system point cloud processing (10)
- Project training of Software College of Shandong University rendering engine system radiation pre calculation (VIII)
- 5g new scheme! Upgrade the existing base station and UE simulator to 5g millimeter wave band
- RTOS rt-thread裸机系统与多线程系统
- The small flying page is upgraded to be intelligent and the bug repair is faster
- Project training of Software College of Shandong University rendering engine system basic renderer (IV)
- Unity get local video / download network video
- 从斐波那契数列求和想到的俗手、本手和妙手
- 5-5配置Mysql复制 基于日志点的复制
- [OWT server] customized script 3: server construction
猜你喜欢

Step by step steps to create an ABAP program with a custom screen

Axure RP 9 for Mac(交互式产品原型设计工具)中文版

Office VR porn, coquettish operation! The father of Microsoft hololens resigns!

Applet: how to get the user's mobile number in the plug-in

Axure RP 9 for MAC (interactive product prototyping tool) Chinese version

Huawei equipment is configured with CE dual attribution

< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(三)

【工具推荐】个人本地 markdown 知识图谱软件 Obsidian

Classic case of solidity - Smart games

小飞页升级变智能修复Bug更快速了
随机推荐
Glibc memory management model frees C library memory cache
Dongmingzhu talks about batteries: the most essential thing is safety
In 2021, China's lottery sales generally maintained a rapid growth, and the monthly sales generally tended to be stable [figure]
写代码也有本手俗手之分,而我们要善于发现妙手!
一步步创建包含自定义 Screen 的 ABAP 程序的详细步骤
聊聊事件监听那些事-上
Use of packet capturing tool Fiddler: simulating speed limit test process in weak network environment
Huawei equipment is configured with CE dual attribution
acwing 798二维差分(差分矩阵)
C regular expression
Web UI automation test
[OWT server] customized script 3: server construction
Chapter I linear table
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(七)
Project training of Software College of Shandong University rendering engine system radiation pre calculation (IX)
学习记录[email protected]一文搞懂canvas
Global and Chinese market of vascular prostheses 2022-2028: Research Report on technology, participants, trends, market size and share
Getting started with JMeter
Data analysis | kmeans data analysis
Decision tree classification and examples