nyukat / breast_cancer_classifier

Deep Neural Networks Improve Radiologists' Performance in Breast Cancer Screening

Home Page:https://ieeexplore.ieee.org/document/8861376

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Working with dicom image

eri820503 opened this issue · comments

Hi,

I want to try my dicom image(mammogram) to the model. But I can't find the procedure to transfer dicom image to png file.
I try some procedure to produce the png file:
First, I load dicom image as an array and use Histogram Equalization algorithm(in open cv) to make the contrast as expected.
Then, I save the array as png file with int32 byte.
Finally, I run your code without any error, but I'm not sure the result is correct or not?

Thanks for your contribution!

The way we save png files from dicom images is as shown in the README file:

import png
import pydicom

def save_dicom_image_as_png(dicom_filename, png_filename, bitdepth=12):
    """
    Save 12-bit mammogram from dicom as rescaled 16-bit png file.
    :param dicom_filename: path to input dicom file.
    :param png_filename: path to output png file.
    :param bitdepth: bit depth of the input image. Set it to 12 for 12-bit mammograms.
    """
    image = pydicom.read_file(dicom_filename).pixel_array
    with open(png_filename, 'wb') as f:
        writer = png.Writer(height=image.shape[0], width=image.shape[1], bitdepth=bitdepth, greyscale=True)
        writer.write(f, image.tolist())