139 Star 670 Fork 261

mktime/python-learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
downloads
images
models
qsbk
.gitignore
2.png
ExcelHelper.py
FSM.py
LICENSE
README.md
SSEncrypt.module
ai-agent.py
arch-install.md
audio-rtmp.py
auto_build.py
baidu_ocr.py
balance_config.ini
balance_query.py
balance_query_batch.txt
bencode.py
bloom_1.cpp
bloom_1.py
bloom_2.py
capture-camera.py
check_https_domain_exp_date.py
cnn-demo.py
contacts.xml
crack_test.py
crack_wifi.txt
data-structure.py
dcm2jpg.py
decrypt_remmina.py
delicious.md
delicious.xml
demo.c
dht_client.py
dou2.py
download.py
egcd.py
export_delicious.sh
face-detect.py
fetchurl.py
find_repeat.py
findbig.py
five-elements.py
flv2mp4.py
get_bookmarks.py
get_version.py
gpt35.py
howto_terminate_thread.py
http_proxy.py
i3_config
import_ess_picture.py
ipfind.py
joseph-cycle.py
kimi.py
learn-class.py
learn-docker.md
learn-thread.py
learn_thread.py
linux-tips.md
merge_excel.py
monitor.sh
mydict.py
mysql_init.sql
new.txt
ocr_words.py
orm.py
parse_excel.py
parse_json.py
payload.py
pm25.py
print_ascii.py
problem.py
python-learn-1.py
python-learn-2.py
qiubai.py
remote.sh
repeated.sql
rpc_server.py
scan.py
scan2.py
score.py
screen.sh
send_fangtang.py
sina_user.json
smz_report.py
sock5.py
sock_client.py
sock_serv.py
start-audio.sh
sync_aliyun.py
system_update.py
template.xml
test_img2pdf.py
test_pdf2images.py
torrent_client.py
totp.py
tray.py
update.ico
urls.txt
v2ex.py
v2ex.txt
wifi-keep.sh
wind_crawl.py
x_test.npy
x_train.npy
xml2vcf.py
y_test.npy
y_train.npy
克隆/下载
dcm2jpg.py 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
import pydicom
from PIL import Image
import numpy as np
import os
import sys
''' first: pip install pydicom matplotlib scipy '''
def dicom_file2jpg(infile, outfile):
# 读取DICOM文件
dicom_file = pydicom.read_file(infile)
info = {}
# 通过字典关键字来获取图像的数据元信息(当然也可以根据TAG号)
# 这里获取几种常用信息
info["PatientID"] = dicom_file.PatientID # 患者ID
info["PatientName"] = dicom_file.PatientName # 患者姓名
info["PatientAge"] = dicom_file.PatientAge # 患者年龄
info['PatientSex'] = dicom_file.PatientSex # 患者性别
info['StudyID'] = dicom_file.StudyID # 检查ID
info['StudyDate'] = dicom_file.StudyDate # 检查日期
info['StudyTime'] = dicom_file.StudyTime # 检查时间
info['InstitutionName'] = dicom_file.InstitutionName # 机构名称
info['Manufacturer'] = dicom_file.Manufacturer # 设备制造商
info['StudyDescription']=dicom_file.StudyDescription # 检查项目描述
print(info)
# 将DICOM数据转换为numpy数组
image_array = dicom_file.pixel_array
# 转换为8位图像
image_array = image_array - np.min(image_array)
image_array = image_array / np.max(image_array)
image_8bit = (image_array * 255).astype(np.uint8)
# 转换为PIL图像
image = Image.fromarray(image_8bit)
# 保存为JPEG
image.save(outfile)
def main(name):
fname = name[:-4]
outname = fname + '.jpg'
dicom_file2jpg(name, outname)
if __name__ == '__main__':
if len(sys.argv) < 2:
print('usage: python dicom_file2jpg.py dicom_filefile.dcm')
quit()
main(sys.argv[1])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mktime/python-learn.git
git@gitee.com:mktime/python-learn.git
mktime
python-learn
python-learn
master

搜索帮助