Click or drag to resize

IMcOperationsAvg Method

Averages 2 images, an image and a number, or a list of images.

Namespace:  MediaCy.IQL.Operations
Assembly:  MediaCy.IQL.Operations (in MediaCy.IQL.Operations.dll) Version: 10.0.6912.0
Syntax
VB
Function Avg ( 
	vOperand2 As Object,
	Optional Flags As mcImageCreateFlags = mcImageCreateFlags.mcicfDefault,
	<OptionalAttribute> vOperand1 As Object
) As McImage

Parameters

vOperand2
Type: SystemObject
Second operand of the operation: McImage, number (array of numbers for color images), or an array of McImage or McRegionAccess instances.
Flags (Optional)
Type: MediaCy.IQL.EnginemcImageCreateFlags
Optional image creation flags for the new image if vOperand2 is given as an array of McImage or %McRegionAccess% instances. By default the value is zero, which creates a visible image that is part of the Images collection. See %mcImageCreateFlags% for the list of supported flags.
vOperand1 (Optional)
Type: SystemObject
Optional first image operand (operator applies to parent image when parameter is omitted), or a number (an array of numbers for color images). This image must be given if there is no parent image, unless vOperand2 is given as an array of McImage or McRegionAccess instances. If given, this image determines the type of the resulting average; other images are cast to this type, honoring the Conversion property. If not given, then the destination type is that of the parent image or the first image in the vOperand2 array if there is no parent.

Return Value

Type: McImage
The destination, averaged, McImage. This will be a new image if vOperand2 is given as an array of McImage or %McRegionAccess% instances, otherwise it will be the parent image or vOperand1 if there is no parent.
Remarks
A conversion is performed on vOperand2 so that it has the same type as the destination image (vOperand1 if it is given, the parent image otherwise). The conversion rules are defined by the value of the Conversion property. For 2 images or 1 image and a number, the result is: ( Parent image [or vOperand1] + vOperand2 ) / 2 which is stored in the parent image or vOperand1 if there is no parent. When vOperand2 is an array of images, the result is: ( Parent image [or vOperand1] + vOperand2[0] + vOperand2[1] + ...) / ( Size (vOperand2) + 1 ) and a new image is returned. If an array of images (or %McRegionAccess% instances) is supplied, then the returned image will have as many frames as the shortest ActiveFrameRange in any of the images, and its size will be the smallest size of the sizes of the Aoi of any of the sources. For floating point image types, the stored results may exceed the bounds of the current destination McImage.RangeMin to McImage.RangeMax. These range properties are not changed automatically.
Examples
VB
'Example 1. Average Images(0) with ActiveImage; place result in ActiveImage
ThisApplication.ActiveImage.Op.Avg Images(0)
'Example 2. Average all images, counting the ThisApplication.ActiveImage only once
' vOperand2 is array of Variant's holding image names; e.g., Images.Item("Name")
ReDim varrImages(0 To Images.Count - 2) As Variant ' room for all images less the ActiveImage
Dim nIm As Long
For Each varImage In ThisApplication.Images
If Not varImage Is ThisApplication.ActiveImage Then
varrImages(nIm) = varImage.Name 'add the name to the list
' Set varrImages(nIm) = varImage ' this would be faster and cleaner,
' but we want to illustrate the array of names approach
nIm = nIm + 1
End If ' this image is not the ActiveImage
Next varImage
'Use the child of the ThisApplication.ActiveImage.  Cast to type of ActiveImage
ThisApplication.ActiveImage.Op.Avg varrImages
'Example 3. Average all images using a global McOperations instance
' vOperand 2 is Array of McImage instances
ReDim arrImages(0 To ThisApplication.Images.Count - 1) As McImage
Dim nI As Long
nI = 0
For Each varImage In Images
Set arrImages(nI) = varImage
nI = nI + 1
Next varImage
'Create a global McOperations operator with no parent McImage
Dim globalOp As McOperations
Set globalOp = CreateOperator("McOperations") 'No parent McImage, no name
globalOp.Avg arrImages 'Pass in array
Set globalOp = Nothing
See Also