Vane Data / API 参考
IMAGE 访问器
image_width、image_height、image_channel、image_mode 和 image_attribute 读取 IMAGE 元数据,不解码像素、不打开文件。它们属于基础引擎,返回 UINTEGER,不受 image_backend 影响。
签名
vane.image_width(image) -> Expression vane.image_height(image) -> Expression vane.image_channel(image) -> Expression vane.image_mode(image) -> Expression vane.image_attribute(image, name) -> Expression
SQL:image_width(image)、image_height(image)、image_channel(image)、image_mode(image) 和 image_attribute(image, name)。五个函数都有 Expression 方法。
参数
| 函数 | 返回 |
|---|---|
| image_width(image) | 像素宽度 |
| image_height(image) | 像素高度 |
| image_channel(image) | 通道数 |
| image_mode(image) | 数值模式编码(见下表) |
| image_attribute(image, name) | 由 name 指定的属性:height、width、channel 或 mode |
image_mode 返回模式编码,编码顺序覆盖全部十种模式:
| 模式 | 编码 | 通道 | 像素 dtype |
|---|---|---|---|
| L | 1 | 1 | UInt8 |
| LA | 2 | 2 | UInt8 |
| RGB | 3 | 3 | UInt8 |
| RGBA | 4 | 4 | UInt8 |
| L16 | 5 | 1 | UInt16 |
| LA16 | 6 | 2 | UInt16 |
| RGB16 | 7 | 3 | UInt16 |
| RGBA16 | 8 | 4 | UInt16 |
| RGB32F | 9 | 3 | Float32 |
| RGBA32F | 10 | 4 | Float32 |
返回值与错误
每个访问器返回 UINTEGER;NULL 输入返回 NULL。image_attribute 遇到未知属性名会报错。
示例
import vane con = vane.connect() con.sql(""" SELECT image_width(image) AS width, image_height(image) AS height, image_channel(image) AS channels, image_mode(image) AS mode FROM (SELECT decode_image_file(image_file('photo.png')) AS image) """).show()