code: def open_image(fn):
      
      flags = cv2.IMREAD_UNCHANGED+cv2.IMREAD_ANYDEPTH+cv2.IMREAD_ANYCOLOR
      if not os.path.exists(fn) and not str(fn).startswith("http"):
          raise OSError('No such file or directory: {}'.format(fn))
      elif os.path.isdir(fn) and not str(fn).startswith("http"):
          raise OSError('Is a directory: {}'.format(fn))
      elif isdicom(fn):
          slice = pydicom.read_file(fn)
          if slice.PhotometricInterpretation.startswith('MONOCHROME'):
              # Make a fake RGB image
              im = np.stack([slice.pixel_array]*3,-1)
              return im / ((1 << slice.BitsStored)-1)
          else:
              # No support for RGB yet, as it involves various color spaces.
              # It shouldn't be too difficult to add though, if needed.
              raise OSError('Unsupported DICOM image with PhotometricInterpretation=={}'.format(slice.PhotometricInterpretation))
      else:
          #res = np.array(Image.open(fn), dtype=np.float32)/255
          #if len(res.shape)==2: res = np.repeat(res[...,None],3,2)
          #return res
          try:
              if str(fn).startswith("http"):
                  req = urllib.urlopen(str(fn))
                  image = np.asarray(bytearray(req.read()), dtype="uint8")
                  im = cv2.imdecode(image, flags).astype(np.float32)/255
              else:
                  im = cv2.imread(str(fn), flags).astype(np.float32)/255
              if im is None: raise OSError(f'File not recognized by opencv: {fn}')
              return cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
          except Exception as e:
              raise OSError('Error handling image at: {}'.format(fn)) from e
docs: Opens an image using OpenCV given the file path.
  
      Arguments:
          fn: the file path of the image
  
      Returns:
          The image in RGB format as numpy array of floats normalized to range between 0.0 - 1.0