stanfordmlgroup / chexpert-labeler

CheXpert NLP tool to extract observations from radiology reports.
MIT License
328 stars 78 forks source link

convert dicom to jpg #11

Closed zunzhumu closed 4 years ago

zunzhumu commented 4 years ago

Sir,how do you convert the original dicom data to JPG image? Thanks.

jirvin16 commented 4 years ago

This repository is for the NLP tool to extract observations from radiology reports, but for the image processing we used this code:

# Read the DICOM and extract the image.
import pydicom
import cv2

dcm_file = pydicom.dcmread(dcm_file_path)
raw_image = dcm_file.pixel_array

# Normalize pixels to be in [0, 255].
rescaled_image = cv2.convertScaleAbs(dcm_file.pixel_array,
                                     alpha=(255.0/dcm_file.pixel_array.max()))

# Correct image inversion.
if dcm_file.PhotometricInterpretation == "MONOCHROME1":
   rescaled_image = cv2.bitwise_not(rescaled_image)

# Perform histogram equalization.
adjusted_image = cv2.equalizeHist(rescaled_image)

cv2.imwrite(output_file_path, adjusted_image)
zunzhumu commented 4 years ago

I got it, thank you!