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