The research of python--dicom image

Source: Internet
Author: User
Tags install matplotlib
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:

1 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, #后来我在找到这种pip的安装方法, pro-Test available
1 pip Install pydicom
1 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:

 1 #-*-coding:utf-8-*-2 Import cv2 3 import numpy 4 import dicom 5 from matplotlib import Pyplot as PLT 6 7 DCM = Dicom. Read_file ("AT0001_100225002.DCM") 8 dcm.image = Dcm.pixel_array * DCM. Rescaleslope + DCM. Rescaleintercept 9 slices = []11 slices.append (DCM)-img = slices[int (len (slices)/2)].image.copy () ret,img = cv2.t Hreshold (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:19 cv2.fillpoly (mask, [con Tour], 255) img[(Mask > 0)] = 25521 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)] = -200029 plt.figure (Figsize= ()) Plt.subplot (131) plt.imshow (Slices[int (len (slices)/2)].image, ' Gray ') plt.title (' Original ') ) Plt.subplot (plt.imshow) (iMG, ' Gray ') Notoginseng 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.

1 Import dicom 2 import JSON 3 def loadfileinformation (filename): 4     information = {} 5     ds = Dicom.read_file (Filena Me) 6     information[' patientid ' = ds. Patientid 7     information[' patientname '] = ds. Patientname 8     information[' patientbirthdate '] = ds. Patientbirthdate 9     information[' patientsex '] = ds. PatientSex10     information[' studyid '] = ds. StudyID11     information[' studydate '] = ds. StudyDate12     information[' studytime '] = ds. StudyTime13     information[' institutionname '] = ds. InstitutionName14     information[' manufacturer '] = ds. Manufacturer15     Print dir (ds)-     Print type (information)-     return information18 a= Loadfileinformation (' AT0001_100225002.DCM ') print a
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.