import cv2 import numpy import pydicom from matplotlib import pyplot as plt

dcm = pydicom.read_file("AT0001_100225002.DCM") dcm.image = dcm.pixel_array * dcm.RescaleSlope + dcm.RescaleIntercept slices = [] slices.append(dcm) img = slices[int(len(slices)/2)].image.copy() ret, img = cv2.threshold(img, 90, 3071, cv2.THRESH_BINARY) img = numpy.uint8(img) contours, _ = cv2.findContours(img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) mask = numpy.zeros(img.shape, numpy.uint8) for contour in contours: cv2.fillPoly(mask, [contour], 255) img[(mask > 0)] = 255 kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (2, 2)) img = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel) img2 = slices[int(len(slices)/2)].image.copy() img2[(img == 0)] = -2000 plt.figure(figsize=(12, 12)) plt.subplot(131) plt.imshow(slices[int(len(slices) / 2)].image, 'gray') plt.title('Original') plt.subplot(132) plt.imshow(img, 'gray') plt.title('Mask') plt.subplot(133) plt.imshow(img2, 'gray') plt.title('Result') plt.show()

import pydicom import json

def loadFileInformation(filename): information = {} ds = pydicom.read_file(filename) information['PatientID'] = ds.PatientID information['PatientName'] = ds.PatientName information['PatientBirthDate'] = ds.PatientBirthDate information['PatientSex'] = ds.PatientSex information['StudyID'] = ds.StudyID information['StudyDate'] = ds.StudyDate information['StudyTime'] = ds.StudyTime information['InstitutionName'] = ds.InstitutionName information['Manufacturer'] = ds.Manufacturer print(dir(ds)) print(type(information)) return information

a = loadFileInformation('AT0001_100225002.DCM') print(a)

import cv2import numpyimport dicomfrom matplotlib import pyplot as pltdcm = dicomread_fileAT0001_100225002DCMdcmimage = dcmpixel_array dcmRescaleSlope + dcmRescaleInterceptslices = slicesappenddcmimg

原文地址: http://www.cveoy.top/t/topic/biwR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录