Operator ConvertPixelFormat

Operator Library: Base

Operator ConvertPixelFormat 會盡可能保留最多資訊,同時將 Arithmetic 與 Bit Width 調整為所需的輸出 Pixel Format。 因此,該 operator 允許在輸出 link 上定義 Bit Width 與 Arithmetic。

該演算法的主要原則包含兩個部分:

  1. 透過裁切來更改 Arithmetic
    • unsigned 轉 signed:輸出端的 MSB 會被用作正負號位元
    • signed 轉 unsigned:將數值裁切至正數範圍,亦即若數值小於 0 則設為零
  2. 在保持相對亮度的同時更改 Bit Width
    • 如果增加了輸出 Bit Width,數值會向左位移以符合所需的 Bit Width
    • 如果減少了輸出 Bit Width,數值會被除以特定倍數並四捨五入以符合所需的 Bit Width

因此,輸出數值可以透過以下方式決定:

Input Bit Width Output Bit Width Input Arithmetic Output Arithmetic Input Value 輸出值 Comment
Decimal Binary Decimal Binary
4 5 unsigned unsigned 10 1010 20 10100 value * 2
5 4 unsigned unsigned 15 1111 8 1000 value divided by 2 and rounded
5 4 unsigned unsigned 31 11111 15 1111 value clipped to maximum
4 4 unsigned signed 11 1011 6 0100 value divided by 2 and rounded
4 4 signed unsigned 4 0100 8 1000 value * 2
5 4 signed unsigned 10 01010 10 1010 value kept
5 4 signed unsigned -2 11110 0 0000 數值會被截斷至 0
5 4 signed signed -7 11001 -4 1100 value divided by 2 and rounded

表 34. 範例


對於色彩連線,每個色彩分量都會被個別處理。

I/O Properties

Property Value
Operator Type O
Input Link I, data input
Output Link O, data output

支援的 Link 格式

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 運算子的使用方式: