The operator CastBitWidth changes the bit width by selecting the lower bits of the input. If the output bit width is greater than the input bit width, the value is kept i.e. bit are added to the most significant bits. A sign extension is performed for signed value. If the output bit width is less than the input bit width, the most significant bits are discarded. The value changes to

i.e. only the remaining bits are used. Output bit width is defined by
.
For color values, each component is processed individually.
Use the operator with care. Only discard bits if you know you will not require them. The operator might destroy your values.
Input Bit Width | Input Value | Arithmetic | Output Bit Width | Output Value | Comment | ||
---|---|---|---|---|---|---|---|
Decimal | Binary | Decimal | Binary | ||||
5 | 10 | 01010 | unsigned | 4 | 10 | 1010 | value is kept |
5 | 10 | 01010 | unsigned | 3 | 2 | 010 | value is changed |
5 | 10 | 01010 | signed | 6 | 10 | 001010 | value is kept |
5 | -10 | 10110 | signed | 6 | -10 | 110110 | value is kept, sign extension |
5 | 10 | 01010 | signed | 4 | -6 | 1010 | value is changed |
5 | -10 | 10110 | signed | 4 | 6 | 0110 | value is changed |
Table 20. Examples
The range of the input bit width is [1, 64]. For signed inputs, the range is [2, 64]. For unsigned color inputs, the range is [3, 63] and for signed color, the range is [6, 63]. |
|
The range of the output bit width is [1, 64]. For signed outputs, the range is [2, 64]. For unsigned color outputs, the range is [3, 63] and for signed color, the range is [6, 63]. |
The use of operator CastBitWidth is shown in the following examples:
-
Figure 176, 'ShiftLeft Operator Added for 16Bit Output'
Tutorial - User ShiftLeft to change DMA bit width.
-
'Combine Image Data From Two Camera Sources - Building an Overlay Blend'
Tutorial - From equation to implementation. Explanation on how to implement the overlay blend.
-
Examples - A high speed and robust laser line detection algorithm. The algorithm determines center of gravity coordinates to obtain sub-pixel resolution results.
-
Example - Histogram thresholding
-
Examples - Shows the usage of operator Blob_Analysis_2D. The applet binarizes the input data and determines the blob analysis results. The results as well as the original image are output using two DMA channels.
-
Examples - The blob analysis operator is applied to an input camera image. The applet shows the usage of the blob data in the applet. In this case, the object with the maximum are is localized and the coordinates are used to cut out the object from the original image.
-
Examples - The applet shows an example for white balancing on RGB images.
-
Examples - The Kirsch filter is a good edge detection filter for non directional edges.
-
Examples - A Sobel filter in x-direction only.
-
Examples - A Sobel filter in all 4 directions.
-
Examples - A simple 3x3 box filter.
-
Examples - A Gauss filter using a 5x5 kernel.
-
Examples - An example of the use of two filters in parallel.
-
Examples - Downsampling by factor 3x3 without the use of operator SampleDn.
-
Examples - Shows how to vertically mirror an image. Note the mirroring of the parallel words and the pixel.
-
'High Dynamic Range and Low Dynamic Range Example Using Camera Response Function'
Examples - High Dynamic Range According to Debevec
-
'High Dynamic Range and Low Dynamic Range Example with a Weighted Linear Ansatz'
Examples - High Dynamic Range with Linear Ansatz
-
'2D Shading Correction / Flat Field Correction'
Examples - The example shows the implementation of a 2D shading correction. Correction values are stored in frame grabber RAM. The applet performs a high precision offset and gain correction.
-
'1D Shading Correction Using Block RAM'
Examples - The example shows an 1D shading correction. The correction values are stored in block RAM memory.
-
'1D Shading Correction Using Frame Grabber RAM'
Examples - The example shows an 1D shading correction. The correction values are stored in Frame Grabber RAM.