利用python实现.dcm格式图像转为.jpg格式
作者:朴素.无恙 时间:2021-08-28 04:16:35
如下所示:
import pydicom
import matplotlib.pyplot as plt
import scipy.misc
import pandas as pd
import numpy as np
import os
def Dcm2jpg(file_path):
#获取所有图片名称
c = []
names = os.listdir(file_path) #路径
#将文件夹中的文件名称与后边的 .dcm分开
for name in names:
index = name.rfind('.')
name = name[:index]
c.append(name)
for files in c :
picture_path = "/home/dell/Desktop/Dcm/"+files+".dcm"
out_path = "/home/dell/Desktop/Dcm1/"+files+".jpg"
ds = pydicom.read_file(picture_path)
img = ds.pixel_array # 提取图像信息
scipy.misc.imsave(out_path,img)
print('all is changed')
Dcm2jpg('/home/dell/Desktop/Dcm')
在此处需要安装pydicom库,直接在终端命令窗口使用pip install pydicom命令安装
将.bmp格式图片转为.jpg图像
#import scipy.misc
import os
from PIL import Image
def bmp2jpg(file_path,out_path):
#获取所有图片名称
c = []
names = os.listdir(file_path) #路径 #将文件夹中的文件名称与后边的 .bmp分开
for name in names:
index = name.rfind('.')
name = name[:index]
c.append(name)
for files in c :
picture_path = "/home/dell/Desktop/unet/d/Mask/"+files+".bmp"
out_path = "/home/dell/Desktop/unet/d/Mask1/"+files+"_mask.gif"
im = Image.open(picture_path)
im.save(out_path)#scipy.misc.imsave(out_path,im)
print('all is changed')
bmp2jpg('/home/dell/Desktop/unet/d/Mask','/home/dell/Desktop/unet/d/Mask1')
来源:https://blog.csdn.net/weixin_40123108/article/details/86649065
标签:python,.dcm格式,图像,.jpg格式
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server连接失败错误及解决
2008-01-28 21:09:00
![](https://img.aspxhome.com/file/UploadPic/20081/28/2008128211959685s.jpg)
SQL存储过程初探
2009-09-09 14:22:00
![](https://img.aspxhome.com/file/UploadPic/20099/9/cccr-25s.jpg)
Python3 mmap内存映射文件示例解析
2021-07-14 15:05:50
![](https://img.aspxhome.com/file/2023/1/66891_0s.png)
python Multiprocessing.Pool进程池模块详解
2023-08-25 09:24:59
解决Python selenium get页面很慢时的问题
2022-08-29 02:08:22
![](https://img.aspxhome.com/file/2023/6/90596_0s.jpg)
如何基于python实现年会抽奖工具
2022-01-28 04:24:42
sqlserver 2000中创建用户的图文方法
2012-03-26 18:26:39
access MDB 转换为 Execl(ASP类)
2008-07-19 12:10:00
DIV与Table布局在大型网站的可用性比较
2007-10-08 12:46:00
![](https://img.aspxhome.com/file/UploadPic/200710/8/2007108125233616s.jpg)
asp三天学好ADO对象之第一天
2008-10-09 12:46:00
Windows下Python使用Pandas模块操作Excel文件的教程
2021-01-05 23:07:40
![](https://img.aspxhome.com/file/2023/1/69021_0s.jpg)
Python dict和defaultdict使用实例解析
2022-12-24 20:44:19
![](https://img.aspxhome.com/file/2023/1/80631_0s.png)
python异常和文件处理机制详解
2023-12-13 11:46:13
server application error--IIS故障
2009-06-11 12:50:00
django 在原有表格添加或删除字段的实例
2023-11-25 04:21:08
用Python实现读写锁的示例代码
2022-09-19 13:51:01
Sql server 2005 找出子表树
2008-11-24 15:23:00
简单好用的PHP分页类
2023-11-22 09:32:39
![](https://img.aspxhome.com/file/2023/6/111676_0s.jpg)
如何将 awk 脚本移植到 Python
2022-02-28 05:40:52
Python数据分析之使用scikit-learn构建模型
2023-11-10 23:19:10
![](https://img.aspxhome.com/file/2023/5/64365_0s.jpg)