Image transformation and codec
Functions for image encoding and decoding, format conversion, resizing, and pixel processing.
The functions in this topic are provided by the Python multimodal function library (VVR 11.8+). Load the module at the beginning of the SQL job before use:
LOAD MODULE python;
USE MODULES python, core;
For complete examples and the IMAGE type, see Image function overview.
Function summary
|
Function |
Description |
|
Decodes raw image bytes into IMAGE |
|
|
Encodes a decoded image into compressed bytes or a Data URL |
|
|
Recompresses encoded image bytes |
|
|
encodingformat |
|
|
imagemode |
|
|
size |
|
|
Scale proportionally |
|
|
image |
|
|
Detect and crop black borders |
|
|
image |
|
|
processing |
|
|
, and and |
|
|
image |
IMAGE_DECODE
Decodes raw image bytes into IMAGE.
IMAGE_DECODE(image_bytes [, on_error [, mode [, pixel_limit]]])
|
Parameter |
Type |
Default |
Description |
|
image_bytes |
|
Required |
encoding imagebytes. |
|
on_error |
|
|
image errorprocessing. |
|
mode |
|
|
mode. |
|
pixel_limit |
|
|
pixel, pixel image on_error processing. |
Return type: IMAGE
SELECT IMAGE_METADATA(IMAGE_DECODE(img_bytes, 'null', 'RGB')).mode
FROM raw_images;
IMAGE_ENCODE
decoding Image encoding compressionbytes, or encoding Base64 Data URL string.
IMAGE_ENCODE(image_input [, format [, quality [, output]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
format |
|
|
format ( Note
JPEG format, encoding RGBA image JPEG RGB. |
|
quality |
|
|
compression, |
|
output |
|
|
output. |
Return type: BYTES or STRING.
SELECT
IMAGE_ENCODE(IMAGE_DECODE(img_bytes), 'PNG') AS png_bytes,
IMAGE_ENCODE(IMAGE_DECODE(img_bytes), 'PNG', 85, 'data_url') AS png_url
FROM raw_images;
IMAGE_COMPRESS
Recompresses encoded image bytes into a specified format and quality.
IMAGE_COMPRESS(image_bytes [, quality [, format]])
|
Parameter |
Type |
Default |
Description |
|
image_bytes |
|
Required |
encoding imagebytes. |
|
quality |
|
|
compression, |
|
format |
|
|
outputformat ( |
Return type: BYTES
SELECT IMAGE_COMPRESS(img_bytes, 60, 'JPEG') FROM raw_images;
IMAGE_CONVERT_FORMAT
Converts encoded image bytes into a different encoding format.
IMAGE_CONVERT_FORMAT(image_bytes, output_format)
|
Parameter |
Type |
Default |
Description |
|
image_bytes |
|
Required |
encoding imagebytes. |
|
output_format |
|
Required |
format ( |
Return type: BYTES
SELECT IMAGE_CONVERT_FORMAT(img_bytes, 'JPEG') FROM raw_images;
IMAGE_CONVERT_MODE
image mode.
IMAGE_CONVERT_MODE(image_input, mode)
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
mode |
|
Required |
mode. |
Return type: IMAGE
SELECT IMAGE_METADATA(IMAGE_CONVERT_MODE(IMAGE_DECODE(img_bytes), 'L')).channels
FROM raw_images;
IMAGE_RESIZE
image size.
IMAGE_RESIZE(image_input, width, height [, method])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
width |
|
Required |
width (pixel). |
|
height |
|
Required |
height (pixel). |
|
method |
|
|
: |
Return type: IMAGE
SELECT IMAGE_ENCODE(IMAGE_RESIZE(IMAGE_DECODE(img_bytes), 512, 512), 'JPEG', 85)
FROM raw_images;
IMAGE_RESCALE
image.
IMAGE_RESCALE(image_input, scale [, method])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
scale |
|
Required |
, |
|
method |
|
|
: |
Return type: IMAGE
SELECT IMAGE_METADATA(IMAGE_RESCALE(IMAGE_DECODE(img_bytes), 0.5)).width FROM raw_images;
IMAGE_CROP
image.
IMAGE_CROP(image_input [, crop_coords [, crop_type [, crop_ratio [, crop_size]]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
crop_coords |
|
|
pixel |
|
crop_type |
|
|
. |
|
crop_ratio |
|
|
Note
If you configure the |
|
crop_size |
|
|
outputsize |
Return type: IMAGE
For coordinate-based cropping, and for center cropping whose output size is larger than the original image, areas outside the original image are filled with zero-value pixels. Ratio-based cropping never exceeds the original image.
SELECT IMAGE_CROP(img, ARRAY[10, 10, 210, 210]) FROM images;
SELECT IMAGE_CROP(
img,
CAST(NULL AS ARRAY<INT>),
'ratio',
ARRAY[0.5, 0.5]
) FROM images;
IMAGE_CROP_BLACK_BORDER
image.
IMAGE_CROP_BLACK_BORDER(image_input [, detect_algorithm [, black_threshold
[, edge_sensitivity [, min_border_size]]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
detect_algorithm |
|
|
algorithm: |
|
black_threshold |
|
|
threshold, pixel value. |
|
edge_sensitivity |
|
|
The edge detection sensitivity. |
|
min_border_size |
|
|
pixelwidth. |
Return type: IMAGE
SELECT IMAGE_CROP_BLACK_BORDER(img, 'threshold', 10) FROM images;
IMAGE_FLIP
image.
IMAGE_FLIP(image_input [, mode])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
mode |
|
|
: |
Return type: IMAGE
SELECT IMAGE_FLIP(img, 'vertical') FROM images;
IMAGE_BLUR
image processing.
IMAGE_BLUR(image_input [, radius [, blur_type]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
radius |
|
|
The blur radius must be a non-negative number. This parameter does not take effect in |
|
blur_type |
|
|
algorithm:
|
Return type: IMAGE
SELECT IMAGE_ENCODE(IMAGE_BLUR(img, 5), 'PNG') FROM images;
IMAGE_ADJUST_COLOR
, and and.
IMAGE_ADJUST_COLOR(image_input [, brightness [, contrast [, saturation]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
brightness |
|
|
, value 0. 1.0. |
|
contrast |
|
|
, value 0. 1.0. |
|
saturation |
|
|
and, value 0. 1.0. |
Return type: IMAGE
For images in L16 mode, the adjustment factor parameter is not supported.
SELECT IMAGE_ADJUST_COLOR(img, 1.2, 1.0, 1.0) FROM images;
IMAGE_REMOVE_BACKGROUND
image, Returns or image.
IMAGE_REMOVE_BACKGROUND(image_input [, alpha_matting
[, alpha_matting_foreground_threshold
[, alpha_matting_background_threshold
[, alpha_matting_erode_size [, bgcolor]]]]])
|
Parameter |
Type |
Default |
Description |
|
image_input |
|
Required |
The decoded image. |
|
alpha_matting |
|
|
alpha matting,. |
|
alpha_matting_foreground_threshold |
|
|
Alpha matting threshold, valuerange |
|
alpha_matting_background_threshold |
|
|
Alpha matting threshold, valuerange |
|
alpha_matting_erode_size |
|
|
Alpha matting size, integer. |
|
bgcolor |
|
|
RGBA, |
Return type: IMAGE
SELECT IMAGE_REMOVE_BACKGROUND(img, FALSE, 240, 10, 10, ARRAY[255, 255, 255, 255])
FROM images;