ImageDecoder#
Domain:
ai.onnxSince version: 20
Loads and decodes and image from a file. If it can’t decode for any reason (e.g. corrupted encoded stream, invalid format, it will return an empty matrix). The following image formats are supported:
BMP
JPEG (note: Lossless JPEG support is optional)
JPEG2000
TIFF
PNG
WebP
Portable image format (PBM, PGM, PPM, PXM, PNM)
Decoded images follow a channel-last layout: (Height, Width, Channels). JPEG chroma upsampling method: When upsampling the chroma components by a factor of 2, the pixels are linearly interpolated so that the centers of the output pixels are 1/4 and 3/4 of the way between input pixel centers. When rounding, 0.5 is rounded down and up at alternative pixels locations to prevent bias towards larger values (ordered dither pattern). Considering adjacent input pixels A, B, and C, B is upsampled to pixels B0 and B1 so that
B0 = round_half_down((1/4) * A + (3/4) * B)
B1 = round_half_up((3/4) * B + (1/4) * C)
This method, is the default chroma upsampling method in the well-established libjpeg-turbo library, also referred as “smooth” or “fancy” upsampling.
Inputs
encoded_stream (T1): Encoded stream
Outputs
image (T2): Decoded image
Type Constraints
T1: Constrain input types to 8-bit unsigned integer tensor. Allowed types: tensor(uint8).
T2: Constrain output types to 8-bit unsigned integer tensor. Allowed types: tensor(uint8).
Examples#
test_cc_image_decoder_decode_bmp_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(3126,), dtype=uint8
[66, 77, 54, ..., 0, 0, 0]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
...,
[[ 24, 246, 11],
[ 24, 246, 11],
[ 24, 246, 11],
...,
[240, 63, 27],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]]]
test_cc_image_decoder_decode_jpeg2k_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(1887,), dtype=uint8
[ 0, 0, 0, ..., 151, 255, 217]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
...,
[[ 24, 246, 11],
[ 24, 246, 11],
[ 24, 246, 11],
...,
[240, 63, 27],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]]]
test_cc_image_decoder_decode_jpeg_bgr
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "BGR"
Inputs:
data: shape=(1058,), dtype=uint8
[255, 216, 255, ..., 216, 255, 217]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[255, 73, 230],
[255, 76, 227],
[255, 81, 222],
...,
[ 76, 154, 66],
[ 0, 9, 0],
[ 9, 0, 15]],
[[255, 77, 232],
[255, 79, 228],
[254, 83, 221],
...,
[ 71, 151, 62],
[ 0, 9, 0],
[ 5, 0, 11]],
[[255, 81, 234],
[255, 82, 229],
[250, 86, 221],
...,
[ 66, 151, 59],
[ 0, 16, 0],
[ 0, 13, 0]],
...,
[[ 58, 234, 37],
[ 60, 233, 45],
[ 58, 225, 55],
...,
[ 47, 79, 168],
[ 0, 13, 50],
[ 0, 1, 10]],
[[ 0, 28, 0],
[ 0, 25, 0],
[ 0, 19, 0],
...,
[ 0, 1, 31],
[ 0, 1, 0],
[ 7, 5, 0]],
[[ 0, 2, 0],
[ 0, 0, 3],
[ 4, 0, 10],
...,
[ 11, 6, 8],
[ 14, 5, 0],
[ 27, 16, 0]]]
test_cc_image_decoder_decode_jpeg_grayscale
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "Grayscale"
Inputs:
data: shape=(1058,), dtype=uint8
[255, 216, 255, ..., 216, 255, 217]
Outputs:
output: shape=(32, 32, 1), dtype=uint8
[[[141],
[142],
[143],
...,
[119],
[ 5],
[ 6]],
[[144],
[144],
[144],
...,
[115],
[ 5],
[ 4]],
[[147],
[146],
[145],
...,
[114],
[ 9],
[ 8]],
...,
[[155],
[157],
[155],
...,
[102],
[ 23],
[ 4]],
[[ 16],
[ 15],
[ 11],
...,
[ 10],
[ 1],
[ 4]],
[[ 1],
[ 1],
[ 3],
...,
[ 7],
[ 5],
[ 12]]]
test_cc_image_decoder_decode_jpeg_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(1058,), dtype=uint8
[255, 216, 255, ..., 216, 255, 217]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[230, 73, 255],
[227, 76, 255],
[222, 81, 255],
...,
[ 66, 154, 76],
[ 0, 9, 0],
[ 15, 0, 9]],
[[232, 77, 255],
[228, 79, 255],
[221, 83, 254],
...,
[ 62, 151, 71],
[ 0, 9, 0],
[ 11, 0, 5]],
[[234, 81, 255],
[229, 82, 255],
[221, 86, 250],
...,
[ 59, 151, 66],
[ 0, 16, 0],
[ 0, 13, 0]],
...,
[[ 37, 234, 58],
[ 45, 233, 60],
[ 55, 225, 58],
...,
[168, 79, 47],
[ 50, 13, 0],
[ 10, 1, 0]],
[[ 0, 28, 0],
[ 0, 25, 0],
[ 0, 19, 0],
...,
[ 31, 1, 0],
[ 0, 1, 0],
[ 0, 5, 7]],
[[ 0, 2, 0],
[ 3, 0, 0],
[ 10, 0, 4],
...,
[ 8, 6, 11],
[ 0, 5, 14],
[ 0, 16, 27]]]
test_cc_image_decoder_decode_png_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(312,), dtype=uint8
[137, 80, 78, ..., 66, 96, 130]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
...,
[[ 24, 246, 11],
[ 24, 246, 11],
[ 24, 246, 11],
...,
[240, 63, 27],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]]]
test_cc_image_decoder_decode_pnm_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(3085,), dtype=uint8
[80, 54, 10, ..., 0, 0, 0]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
...,
[[ 24, 246, 11],
[ 24, 246, 11],
[ 24, 246, 11],
...,
[240, 63, 27],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]]]
test_cc_image_decoder_decode_tiff_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(3212,), dtype=uint8
[73, 73, 42, ..., 0, 0, 0]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
[[226, 81, 251],
[226, 81, 251],
[226, 81, 251],
...,
[ 33, 164, 77],
[ 0, 0, 0],
[ 0, 0, 0]],
...,
[[ 24, 246, 11],
[ 24, 246, 11],
[ 24, 246, 11],
...,
[240, 63, 27],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
...,
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]]]
test_cc_image_decoder_decode_webp_rgb
Node:
ImageDecoder(data) -> (output)
Attributes:
pixel_format = "RGB"
Inputs:
data: shape=(552,), dtype=uint8
[82, 73, 70, ..., 0, 0, 0]
Outputs:
output: shape=(32, 32, 3), dtype=uint8
[[[230, 84, 242],
[230, 84, 240],
[232, 84, 238],
...,
[ 48, 155, 87],
[ 0, 13, 0],
[ 0, 0, 0]],
[[229, 84, 244],
[229, 84, 242],
[229, 85, 240],
...,
[ 50, 154, 87],
[ 0, 13, 0],
[ 0, 0, 0]],
[[224, 86, 246],
[224, 86, 246],
[222, 87, 244],
...,
[ 55, 151, 89],
[ 0, 11, 0],
[ 0, 0, 2]],
...,
[[ 60, 221, 53],
[ 58, 222, 51],
[ 58, 223, 47],
...,
[178, 79, 58],
[ 31, 0, 0],
[ 8, 0, 0]],
[[ 0, 24, 0],
[ 0, 25, 0],
[ 0, 27, 0],
...,
[ 29, 0, 0],
[ 10, 0, 0],
[ 2, 0, 0]],
[[ 4, 0, 1],
[ 1, 1, 1],
[ 0, 4, 1],
...,
[ 8, 0, 0],
[ 8, 0, 0],
[ 10, 0, 0]]]