code: def open_dicom(filename) -> PIL.Image:
      bits_stored_key = 0x00280101
      photometric_inter_key = 0x00280004
  
      dcm = pydicom.dcmread(filename)
      bits_stored = dcm[bits_stored_key]
  
      img = dcm.pixel_array
  
      # Check the photometric interpretation
      # MONOCHROME1: Greyscale ranges from bright to dark
      # MONOCHROME2: Greyscale ranges from dark to right
      if dcm[photometric_inter_key].value == "MONOCHROME1":
          img = 2**bits_stored - img
  
      # Apply a VOI LUT transformation (if the image does not
      # contain the needed parameters, the image is returned
      # unchanged)
      img = pydicom.pixel_data_handlers.apply_voi_lut(img, dcm)
  
      img = PIL.Image.fromarray(img)
  
      return img
  
file_path: icevision/icevision/utils/imageio.py
imports: from icevision.imports import *
  from PIL import ExifTags
label_desc: Use image node_id 1 for calling a global function with example usage: open_dicom(filename) and returns: img