MCPcopy Index your code
hub / github.com/databricks/spark-deep-learning / imageArrayToStruct

Function imageArrayToStruct

python/sparkdl/image/imageIO.py:72–89  ·  view source on GitHub ↗

Create a row representation of an image from an image array. :param imgArray: ndarray, image data. :return: Row, image as a DataFrame Row with schema==ImageSchema.

(imgArray, origin="")

Source from the content-addressed store, hash-verified

70
71
72def imageArrayToStruct(imgArray, origin=""):
73 """
74 Create a row representation of an image from an image array.
75
76 :param imgArray: ndarray, image data.
77 :return: Row, image as a DataFrame Row with schema==ImageSchema.
78 """
79 # Sometimes tensors have a leading "batch-size" dimension. Assume to be 1 if it exists.
80 if len(imgArray.shape) == 4:
81 if imgArray.shape[0] != 1:
82 raise ValueError(
83 "The first dimension of a 4-d image array is expected to be 1.")
84 imgArray = imgArray.reshape(imgArray.shape[1:])
85 imageType = _arrayToOcvMode(imgArray)
86 height, width, nChannels = imgArray.shape
87 data = bytearray(imgArray.tobytes())
88 return Row(origin=origin, mode=imageType.ord, height=height,
89 width=width, nChannels=nChannels, data=data)
90
91
92def imageStructToArray(imageRow):

Callers 8

udf_implFunction · 0.90
load_image_uri_implMethod · 0.90
pil_load_spimgMethod · 0.90
keras_load_spimgMethod · 0.90
test_pipelineMethod · 0.90
_resizeImageAsRowFunction · 0.85
_decodeFunction · 0.85

Calls 1

_arrayToOcvModeFunction · 0.85

Tested by 4

pil_load_spimgMethod · 0.72
keras_load_spimgMethod · 0.72
test_pipelineMethod · 0.72