如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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图像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#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' ) |
以上这篇利用python实现.dcm格式图像转为.jpg格式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_40123108/article/details/86649065