【发布时间】:2020-01-22 07:46:39
【问题描述】:
我目前正在开发一个程序,该程序需要我读取 DICOM 文件并正确显示它们。从 DICOM 文件中提取像素数组后,我通过 matplotlib 和 cv2 中的 imshow 函数运行它。令我惊讶的是,它们都产生了截然不同的图像。一个有颜色,另一个没有,一个比另一个显示更多细节。我很困惑为什么会这样。我找到了Difference between plt.show and cv2.imshow? 并尝试将像素转换为 BRG 而不是 cv2 使用的 RGB,但这没有任何改变。我想知道为什么这两个框架以如此不同的方式显示相同的像素缓冲区。下面是我的代码和显示结果的图像
import cv2
import os
import pydicom
import numpy as np
import matplotlib.pyplot as plt
inputdir = 'datasets/dicom/98890234/20030505/CT/CT2/'
outdir = 'datasets/dicom/pngs/'
test_list = [ f for f in os.listdir(inputdir)]
for f in test_list[:1]: # remove "[:10]" to convert all images
ds = pydicom.dcmread(inputdir + f)
img = np.array(ds.pixel_array, dtype = np.uint8) # get image array
rows,cols = img.shape
cannyImg = cv2.Canny(img, cols, rows)
cv2.imshow('thing',cv2.cvtColor(img, cv2.COLOR_BRG2RBG))
cv2.imshow('thingCanny', cannyImg)
plt.imshow(ds.pixel_array)
plt.show()
cv2.waitKey()
【问题讨论】:
标签: python-3.x opencv matplotlib dicom