DICOM (digital Imaging and Communications in Medicine) is the international standard for medical imaging and related information (ISO 12052), which is medical imaging and communication. The following article mainly introduces the python to dicom image reading related data, the need for friends can refer to, the following to see together.
DICOM Introduction
DICOM3.0 images, produced by medical imaging devices to produce standard medical image images, dicom is widely used in radiation medicine, cardiovascular imaging and radiological diagnosis equipment (X-ray, CT, MRI, ultrasound, etc.), and in the field of ophthalmology and dentistry and other medical fields are more and more widely used. In tens of thousands of medical imaging devices, DICOM is one of the most widely deployed medical information standards. There are currently about company aims Yangzhou medical images that meet DICOM standards for clinical use.
Seemingly mysterious image files, exactly how to read it? Online any search, there are many methods, but the lack of comparative system of use, the following comprehensive Baidu information, combined with python2.7, to explain how to read and use DICOM images.
The following libraries are required to read DICOM images: pydicom, CV2, NumPy, Matplotlib. Pydicom specializes in Python-specific packages for DICOM images, numpy efficient processing of scientific computing packages, based on data-drawing libraries.
Installation:
Pip Install Matplotlib
Pip Install Opencv-python #opencv的安装, the basic is to download the package, install the package after the package copied to a folder, #后来我在https://pypi.python.org/pypi/ Opencv-python find the installation method of this Pip, pro-Test available
Pip Install pydicom
Pip Install NumPy
If you do not remember correctly, when installing pydicom, the NumPy will be installed automatically.
Once these libraries are installed, you can manipulate the dicom files.
See the following code specifically:
#-*-coding:utf-8-*-import cv2import numpyimport dicomfrom matplotlib import pyplot as PLTDCM = Dicom.read_file ("AT0001_ 100225002.DCM ") Dcm.image = Dcm.pixel_array * DCM. Rescaleslope + DCM. Rescaleinterceptslices = []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) im2, 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)] = 255kernel = 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)] = -2000plt.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 ()
In the dicom image, a dictionary containing information about the patient can be viewed through dir to see what information the Dicom file has, and the associated value can be returned through the dictionary.
Import dicomimport jsondef loadfileinformation (filename): information = {} ds = Dicom.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 informationa=loadfileinformation (' AT0001_100225002.DCM ') Print a
Summarize