当前位置:网站首页>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 :


边栏推荐
- Saga体系结构模式:微服务架构下跨服务事务的实现
- TS 22.011
- Global and Chinese markets of automatic glue applicators 2022-2028: Research Report on technology, participants, trends, market size and share
- Development practice of ag1280q48 in domestic CPLD
- 面试:为什么整数包装类尽量用equals()来比较大小
- Servlet knowledge explanation (2)
- leetcode-54. Spiral matrix JS
- Keep an IT training diary 067- good people are grateful, bad people are right
- Global and Chinese markets of bioreactors 2022-2028: Research Report on technology, participants, trends, market size and share
- Project training of Software College of Shandong University rendering engine system point cloud processing (10)
猜你喜欢

Explore the Apache shardingsphere SQL parse format function

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

Classic case of solidity - Smart games
![Analysis of China's cargo transport volume, cargo transport turnover and port cargo in 2021 [figure]](/img/ee/ae9984355a98f5529dd4574eea2e7c.jpg)
Analysis of China's cargo transport volume, cargo transport turnover and port cargo in 2021 [figure]

联通网管协议框图

读取mhd、raw图像并切片、归一化、保存

Decision tree classification and examples

Project training of Software College of Shandong University rendering engine system radiation pre calculation (IX)

Axure RP 9 for Mac(交互式产品原型设计工具)中文版
![[browser principle] variable promotion](/img/19/f6b26d97c6024893a21dd40e2bbc47.jpg)
[browser principle] variable promotion
随机推荐
当编程纳入到高考。。。
Redis string type common commands
Classic case of solidity - Smart games
acwing 790. 数的三次方根(浮点数二分)
Escape analysis of golang compiler
Huawei equipment is configured with CE dual attribution
leetcode-54. Spiral matrix JS
C packing and unpacking
Step by step steps to create an ABAP program with a custom screen
acwing795 前缀和(一维)
acwing794 高精度除法
acwing 2816. 判断子序列
一步步创建包含自定义 Screen 的 ABAP 程序的详细步骤
TS 22.011
acwing 802. 区间和 (离散化)
acwing796 子矩阵的和
Analysis of China's cargo transport volume, cargo transport turnover and port cargo in 2021 [figure]
小飞页升级变智能修复Bug更快速了
The nohup command uses
Explore the Apache shardingsphere SQL parse format function