Python threshold segmentation for DICOM images

Source: Internet
Author: User

Python to the dicom image processing, inseparable from the Pydicom,opencv-python,matplotlib,numpy four code base, installed after the completion of the four code base,

The dicom image can be read, and the image is processed, the result is explicitly processed, the following examples illustrate:

ImportCv2ImportNumPyImportdicom fromMatplotlibImportPyplot as Plt#reading a single dicom imageDCM = Dicom.read_file (".. /DATA/VHM.420.DCM") Dcm.image= Dcm.pixel_array * DCM. Rescaleslope +DCM. Rescaleintercept#get pixel data in an imageslices =[]slices.append (DCM)#copying pixel data in dicom imagesimg = slices[int (len (slices)/2)].image.copy ()#threshold Segmentation of imagesret,img = Cv2.threshold (IMG, 90,3071, Cv2. Thresh_binary) img=numpy.uint8 (IMG)#extracts the contour from the split result and fills the holeIM2, contours, _ =cv2.findcontours (Img,cv2. Retr_list,cv2. Chain_approx_simple) Mask=Numpy.zeros (Img.shape, numpy.uint8) forContourinchContours:cv2.fillPoly (mask, [contour],255) img[(Mask> 0)] = 255#morphological open operation of the segmentation resultsKernel = cv2.getstructuringelement (cv2. Morph_ellipse, (2,2)) img=Cv2.morphologyex (IMG, Cv2. Morph_open, Kernel)#gets the pixel data of the segmentation result according to the partition maskIMG2 = slices[int (len (slices)/2)].image.copy () img2[(img= = 0)] = 2000#explicit raw data, mask and split resultsPlt.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 ()

Results after the run:

This example takes a single dicom image as an example, splits the skeleton information in the image, and can read multiple DICOM images at the same time, dividing other tissue organs.

Python threshold segmentation for DICOM images

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.