Main principle: adjust the window width of DICOM to make the gray value of each pixel scale to the range of .
The python library used: simpleitk
Here is a demo to convert DICOM (. DCM) images into jpg images:
import SimpleITK as sitk import numpy as np import cv2 def convert_from_dicom_to_jpg(img,low_window,high_window,save_path): lungwin = np.array([low_window*1.,high_window*1.]) Newimg = (IMG lungwin ) / (lungwin  - lungwin ) normalization Newimg = (newimg * 255). Astype ('uint8 ') # extends the pixel value to  cv2.imwrite(save_path, newimg, [int(cv2.IMWRITE_JPEG_QUALITY), 100]) if __name__ == '__main__': #The following is the corresponding DICOM format image into jpg dcm_ image_ path = '/DICOM_ Image / lung001. DCM '# read DICOM file output_jpg_path = 'JPG_image/lung001.jpg' Ds_ array = sitk.ReadImage (dcm_ image_ Path) # read relevant information of DICOM file img_ array = sitk.GetArrayFromImage (ds_ Array) # get array #The coordinate order of image data read by simpleitk is ZYX, that is, from how many slices to the width and height of a single slice. Here we read a single slice, so img_ Shape of array #Similar to (1, height, width) shape = img_array.shape img_ array = np.reshape (img_ Array, (shape , shape ) # get the height and width in the array high = np.max(img_array) low = np.min(img_array) convert_ from_ dicom_ To_ jpg(img_ array, low, high, output_ jpg_ Call the function, convert it to JPG file and save it to the corresponding path print('FINISHED')
The above example of converting DICOM image into JPG image by Python is all the content shared by Xiaobian. I hope it can give you a reference and support developer.