text: # -*- coding: utf-8 -*-
  """dicom2array.ipynb
  
  Automatically generated by Colaboratory.
  
  Original file is located at
      https://colab.research.google.com/drive/1X2haYLq-ZAHy99McB55yHdOyBBI8aPXK
  """
  
  import cv2
  import numpy as np
  import pydicom
  from pydicom.pixel_data_handlers.util import apply_voi_lut
  
  def _dicom2array(path, voi_lut=True, fix_monochrome=True, resize=False):
      dicom = pydicom.read_file(path)
      if voi_lut:
          data = apply_voi_lut(dicom.pixel_array, dicom)
      else:
          data = dicom.pixel_array
      if fix_monochrome and dicom.PhotometricInterpretation == "MONOCHROME1":
          data = np.amax(data) - data
      #Normalize the data: subtract off the minimum, divide by the maximum, convert to 256 uint8
      data = data - np.min(data)
      data = data/np.max(data)
      data = (data * 255).astype(np.uint8)
      
      #Resize images to target value
      if resize:
          data = cv2.resize(data, (256, 256))
      return data