Operator ConvertPixelFormat

Operator Library: Base

运算符 ConvertPixelFormat 尝试在将 Arithmetic 和 Bit Width 调整为所需的目标 Pixel Format 的同时,尽可能保留最多的信息。 因此,该运算符允许在输出链路(output link)上定义 Bit Width 和 Arithmetic。

该算法的基本原理包含两个方面:

  1. 通过截断更改 Arithmetic
    • 无符号转有符号:使用输出端的 MSB 作为符号位
    • 有符号转无符号:截断为正值,即如果值小于 0,则设为零
  2. 通过保持相对亮度来更改 Bit Width
    • 如果输出 Bit Width 增加,则将值左移以满足所需的 Bit Width
    • 如果输出 Bit Width 减少,则将值除以相应数值并四舍五入以满足所需的 Bit Width

因此,输出值可以确定为:

Input Bit Width Output Bit Width 输入 Arithmetic 输出 Arithmetic 输入值 输出值 注释
十进制 二进制 十进制 二进制
4 5 unsigned unsigned 10 1010 20 10100 value * 2
5 4 unsigned unsigned 15 1111 8 1000 value 除以 2 并四舍五入
5 4 unsigned unsigned 31 11111 15 1111 value 截断至最大值
4 4 unsigned signed 11 1011 6 0100 value 除以 2 并四舍五入
4 4 signed unsigned 4 0100 8 1000 value * 2
5 4 signed unsigned 10 01010 10 1010 保持 value
5 4 signed unsigned -2 11110 0 0000 value 截断至 0
5 4 signed signed -7 11001 -4 1100 value 除以 2 并四舍五入

表 34. 示例


对于彩色链路,每个颜色分量均单独进行处理。

I/O Property

Property 值
Operator Type O
Input Link I,数据输入
Output Link O,数据输出

Supported Link Format

Link Parameter Input Link I Output Link O
Bit Width [1, 64]1 [1, 64]2
Arithmetic {unsigned, signed} {unsigned, signed}
Parallelism any as I
Kernel Columns any as I
Kernel Rows any as I
Img Protocol {VALT_IMAGE2D, VALT_LINE1D, VALT_PIXEL0D} as I
Color Format any as I
Color Flavor any as I
Max. Img Width any as I
Max. Img Height any as I

1

输入 Bit Width 的范围是 [1, 64]。对于有符号输入,范围是 [2, 64]。对于无符号彩色输入,范围是 [3, 63],对于有符号彩色输入,范围是 [6, 63]。

2

输出 Bit Width 的范围为 [1, 64]。 对于有符号输出,范围为 [2, 64]。 对于无符号彩色输出,范围为 [3, 63],对于有符号彩色输出,范围为 [6, 63]。

参数

无

使用示例

以下示例展示了运算符 ConvertPixelFormat 的使用方法: