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


边栏推荐
- Global and Chinese market for material injection 2022-2028: Research Report on technology, participants, trends, market size and share
- Scanpy (VI) analysis and visualization of spatial transcriptome data
- Getting started with JMeter
- Global and Chinese markets of bioreactors 2022-2028: Research Report on technology, participants, trends, market size and share
- 从斐波那契数列求和想到的俗手、本手和妙手
- [practical case of light source] UV-LED curing innovation makes the production line more smooth
- (四)GoogleNet複現
- Task output: dense snow ice city theme song 0612
- [weekly replay] game 80 of leetcode
- Axure RP 9 for MAC (interactive product prototyping tool) Chinese version
猜你喜欢

办公室VR黄片,骚操作!微软HoloLens之父辞职!

Solution to idea Chinese prism garbled code error -- console Chinese output prism garbled code

< 山东大学软件学院项目实训 > 渲染引擎系统——点云处理(十)

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

聊聊事件监听那些事-上

Step by step to create a trial version of ABAP program containing custom screen
![In 2021, China's lottery sales generally maintained a rapid growth, and the monthly sales generally tended to be stable [figure]](/img/dd/1bf44d284c709b6bebd4b308ba2cee.jpg)
In 2021, China's lottery sales generally maintained a rapid growth, and the monthly sales generally tended to be stable [figure]

acwing794 高精度除法

线程池执行流程

Introduction and download website of common data of GIS, remote sensing, hydrology and Geography (2), supplementary~
随机推荐
办公室VR黄片,骚操作!微软HoloLens之父辞职!
Getting started with JMeter
Redis General Command
tinyint和int区别
Escape analysis of golang compiler
Why doesn't Alibaba recommend MySQL use the text type?
How to use grafana to easily realize OVL data visualization
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(三)
Project training of Software College of Shandong University rendering engine system basic renderer (6)
< 山东大学软件学院项目实训 > 渲染引擎系统——辐射预计算(八)
[OWT server] customized script 3: server construction
Apache kylin Adventure
小程序:如何在插件中获取用户手机号
< 山东大学软件学院项目实训 > 渲染引擎系统——点云处理(十)
acwing 高精度乘法
Difference between tinyint and int
acwing 800. 数组元素的目标和
2022.02.28 - SX11-05. The largest rectangle in the histogram
Fiddler packet capturing (mobile app)
TS 22.011