Add code to convert DICOM to JPG to this repository
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 3.4k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
At the moment the code used to convert the x-rays from DICOMs to JPGs is not publicly available as it's tied up in another repo. It would be good to have a publicly executable set of code that converts DICOMs to JPGs in the same way as we did to create MIMIC-CXR-JPG from MIMIC-CXR. The core function used was:
import numpy as np
import pydicom
import cv2
def dcm2img(input_file_path, output_file_path):
"""Extract the image from a DICOM and write it to an image file."""
# Read the DICOM and extract the image.
dcm_file = pydicom.dcmread(input_file_path)
raw_image = dcm_file.pixel_array
assert len(raw_image.shape) == 2,\
"Expecting single channel (grayscale) image."
# Normalize pixels to be in [0, 255].
raw_image = raw_image - raw_image.min()
normalized_image = raw_image / raw_image.max()
rescaled_image = (normalized_image * 255).astype(np.uint8)
# Correct image inversion.
if dcm_file.PhotometricInterpretation == "MONOCHROME1":
rescaled_image = cv2.bitwise_not(rescaled_image)
# Perform histogram equalization.
final_image = cv2.equalizeHist(rescaled_image)
# Write the image to file.
cv2.imwrite(output_file_path, final_image)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the repository for existing data-processing entry points and dependency conventions, then use the issue's dcm2img example as the implementation reference. Done means a publicly executable repository component converts the relevant DICOM x-rays to JPGs with the stated grayscale, inversion, normalization, and histogram-equalization behavior; no test file is named, so validation details need to be established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, opencv, python
- Domain
- computer-vision, data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100