Cast Method
Syntax
CWIMAQVision.Cast SourceImage, DestImage, Type [, LookupTable] [, Shift = 0]
Return Type
Long
On success, this method returns 0. On failure, this method returns a negative number.
Purpose
Changes the type of an image.
Remarks
This method operates with all image types.
This method can perform the change directly on the source image, or it can leave the source image unchanged and instead copy the source image to a destination image and then convert the destination image. If the destination image is the same as the source image, the method changes the type of the source image. Otherwise, the method resizes the destination image to the size of source image and then copies the pixels.
To change the type of an image in-place without supplying a shift value or a lookup table, you can set the Type property to the required type. If the source image type and the Type parameter are the same, the method copies pixels unmodified. You can also use Copy to copy pixels without modifying them. If the source image type and the Type parameter are not the same, the method casts the pixel values to the new type as follows:
Source Type |
Type Parameter |
Result |
cwimaqImageTypeU8 |
cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
If you provide a lookup table, the destination pixel will have the lookup value of the source pixel. If you do not provide a lookup table, the method copies the source value to the destination unmodified. |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
cwimaqImageTypeRGB32 |
Each color component of the destination is set to the source value. If the source value is greater than 255, the method sets each color component to 255. If the source value is less than 0, the method sets each color component to 0. |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
cwimaqImageTypeHSL32 |
The method sets the luminance component of the destination to the source value. If the source value is greater than 255, the method sets the luminance to 255. If the source value is less than 0, the method sets the luminance to 0. The method sets hue and saturation component of the destination to 0. If the source image has a specified bit depth, the method uses the bit depth when performing this conversion. |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
cwimaqImageTypeComplex |
The method sets the real component of the destination to the source value. The method sets the imaginary component of the destination to 0. |
cwimaqImageTypeU16 cwimaqImageTypeI16 |
cwimaqImageTypeU8 |
The method right-shifts the source value by the given shift value (divides each source pixel value by 2 shift ) and stores the value in the destination. If the shifted value is greater than 255, the method sets the destination value to 255. If the shift value is zero, the method uses the specified bit depth of the source image. |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
cwimaqImageTypeRGBU64 |
Each color component of the destination is set to the source value. If the source value is greater than 65535, the method sets each color component to 65535. If the source value is less than 0, the method sets each color component to 0. |
cwimaqImageTypeRGBU64 |
cwimaqImageTypeU8 |
The method shifts the source value to the 8-bit range using the specified bit depth of the source image. Then the method sets the destination value to the average of the three color components of the source. |
cwimaqImageTypeRGBU64 |
cwimaqImageTypeI16 cwimaqImageTypeU16 cwimaqImageTypeSGL |
The method sets the destination value to the average of the three color components of the source. If the average of the source color components is out of the range of the destination, the method coerces the average to the range. |
cwimaqImageTypeRGBU64 |
cwimaqImageTypeRGB32 |
The method shifts the source value to the 8-bit range using the specified bit depth of the source image. Then the method sets each color component in the destination value to the corresponding component in the source value. |
cwimaqImageTypeRGBU64 |
cwimaqImageTypeHSL32 |
The method shifts the source value to the 8-bit range using the specified bit depth of the source image. Then the method converts each pixel from the RGB color space to the HSL color space. |
cwimaqImageTypeI16cwimaqImageTypeU16
|
cwimaqImageTypeSGL |
If you provide a lookup table, the destination pixel will have the lookup value of the source pixel. If you do not provide a lookup table, the method copies the source value to the destination unmodified. |
cwimaqImageTypeSGL |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 |
The method sets the destination value to the source value. If the source value is out of the range of the destination, the method coerces the source to the range. |
cwimaqImageTypeRGB32 |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL | The method sets the destination value to the average of the three color components of the source. |
cwimaqImageTypeRGB32 |
cwimaqImageTypeHSL32 |
The method converts each pixel from the RGB color space to the HSL color space. |
cwimaqImageTypeRGB32 cwimaqImageTypeRGBU64 |
cwimaqImageTypeComplex |
The method sets the real portion of the destination value to the average of the three color components of the source, and it sets the imaginary portion of the destination to 0. |
cwimaqImageTypeHSL32 |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
The method sets the destination value to the luminance component of the source value. |
cwimaqImageTypeHSL32 |
cwimaqImageTypeRGB32 |
The method converts each pixel from the HSL color space to the RGB color space. |
cwimaqImageTypeHSL32 |
cwimaqImageTypeComplex |
The method sets the real portion of the destination value to the value of the luminance component of the source, and it sets the imaginary portion of the destination to 0. If the source value is out of the range of the destination, the method coerces the source to the range. |
cwimaqImageTypeComplex |
cwimaqImageTypeU8 cwimaqImageTypeU16 cwimaqImageTypeI16 cwimaqImageTypeSGL |
The method sets the destination value to the magnitude of the source value. If the source value is out of the range of the destination, the method coerces the source to the range. |
cwimaqImageTypeComplex |
cwimaqImageTypeRGB32 cwimaqImageTypeRGBU64 |
The method sets each color component of the destination value to the magnitude of the source value. If the source value is out of the range of the destination, the method coerces the source to the range. |
cwimaqImageTypeComplex |
cwimaqImageTypeHSL32 |
The method sets the luminance component of the destination value to the magnitude of the source value, and it sets the hue and saturation components to 0. If the source value is out of the range of the destination, the method coerces the source to the range. |
cwimaqImageTypeU16 |
cwimaqImageTypeI16 |
The method sets the destination value to the source value. If the source value is out of the range of the destination, the method coerces the source to the range. |
cwimaqImageTypeI16 |
cwimaqImageTypeU16 |
The method sets the destination value to the source value. If the source value is out of the range of the destination, the method coerces the source to the range. |
Parameters
SourceImage As CWIMAQImage
The source image.
DestImage As CWIMAQImage
The destination image.
Type As CWIMAQImageTypes
The new type for the image.
LookupTable As Variant
[Optional] A lookup table. See Remarks for a description of how the method employs the lookup table.
Shift As Variant
[Optional] The shift value for converting 16-bit images to 8-bit images. The method ignores this value for all other conversions. The method executes this conversion by shifting the 16-bit pixel values to the right by the specified number of shift operations, up to a maximum of 8 shift operations, and then truncating to get an 8-bit value. Enter a value of –1 to ignore the bit depth and shift 0. Enter a value of 0 to use the bit depth to cast the image. See Remarks for a description of how the function employs the shift value.
This parameter has a default value of 0.
Example
Dim i As New CWIMAQImage
Dim lookupTable(0 to 255) As Long
Dim index
' Change the image in Viewer1 to an RGB32 image and
' store the results in i
CWIMAQVision1.Cast CWIMAQViewer1.Image, i, cwimaqImageTypeRGB32
' Populate the lookupTable with a form of inverse transformation
For index = 0 to 255
lookupTable(index) = 32767 - (index * 16)
Next
' Change the image in Viewer1 to a 16-bit image using the lookup table
CWIMAQVision1.Cast CWIMAQViewer1.Image, CWIMAQViewer1.Image, _
cwimaqImageTypeI16, lookupTable
' Change the image in Viewer1 to an SGL image
' You can use the Type property on the image since there is no need
' for a lookup table or shift value.
CWIMAQViewer1.Image.Type = cwimaqImageTypeSGL
See Also
Copy
CWIMAQImage.Type