用python将.dcm格式图像转为.jpg格式
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图像