code: def toNDArray(self, image):
          
  
          if not isinstance(image, Row):
              raise TypeError(
                  "image argument should be pyspark.sql.types.Row; however, "
                  "it got [%s]." % type(image))
  
          if any(not hasattr(image, f) for f in self.imageFields):
              raise ValueError(
                  "image argument should have attributes specified in "
                  "ImageSchema.imageSchema [%s]." % ", ".join(self.imageFields))
  
          height = image.height
          width = image.width
          nChannels = image.nChannels
          return np.ndarray(
              shape=(height, width, nChannels),
              dtype=np.uint8,
              buffer=image.data,
              strides=(width * nChannels, nChannels, 1))
docs: Converts an image to an array with metadata.
  
          :param `Row` image: A row that contains the image to be converted. It should
              have the attributes specified in `ImageSchema.imageSchema`.
          :return: a `numpy.ndarray` that is an image.
  
          .. versionadded:: 2.3.0