IMcObjectSelectedValues Property |
![]() |
Namespace: MediaCy.IQL.ObjectManager
Property SelectedValues ( <OptionalAttribute> varSelector0 As Object, <OptionalAttribute> varSelector1 As Object, <OptionalAttribute> varSelector2 As Object, <OptionalAttribute> varSelector3 As Object ) As Object Get Set
' Get histogram values and give a little report. Dim varHistogram As McObject Set varHistogram = GlobalTools.McObjectTemp(ActiveImage.Histogram.Values) Dim varHistValues As McObject varDims = varHistogram.Shape(mcobjSIC_NofDims) If varDims > 1 Then Set varHistValues = GlobalTools.McReduce(varHistogram, , 0) ' Reduce for color images Else Set varHistValues = varHistogram End If varMaxCount = GlobalTools.McMax(varHistValues) Set varHistPeakIndices = GlobalTools.McSqueezeSelector(GlobalTools.McOpEQ(varHistValues, varMaxCount)) Set varSelGE4thOfMax = GlobalTools.McSqueezeSelector(GlobalTools.McOpGE(varHistValues, varMaxCount / 4)) Set varPeakValues = varHistValues.SelectedMcObject(varHistPeakIndices) Debug.Print "Histogram Peak(s) found at " + GlobalTools.McToText(varHistPeakIndices).Value + _ " with count(s) " + GlobalTools.McToText(varPeakValues).Value Debug.Print " Indices with counts 1/4 of Max: " + GlobalTools.McToText(varSelGE4thOfMax).Value Debug.Print " Counts: " + GlobalTools.McToText(varHistValues.SelectedValues(varSelGE4thOfMax)).Value
'This module is SelectionSamples.bas 'It has VB samples for accessing selected subsets 'of the values in Variants and McObjects Option Explicit '***** Variant Examples ******* 'The first set of examples uses native VB arrays (which are 'passed as Variants to methods). Sucessive Sub's get more complex Public Sub SelectFrom1DVariant() Output.Show "Output" Output.Clear Dim var1D As Variant var1D = Array(1, 2, 3, 4, 5) Output.PrintMessage "Select Elements 0,4,2 from (1,2,3,4,5) in that order: " & _ McToText(McOpSelect(var1D, Array(0, 4, 2))) 'show 1 5 3 End Sub 'SelectFrom1DVariant Public Sub AssignToSelectedValuesOf1DVariant() Output.Show "Output" Dim array1D(3) As Long 'length-4 array Dim varT As Variant varT = array1D McOpAssignSelected varT, Array(1, 2), Array(0, 2) Output.PrintMessage "Assigned-to array. " + McToText(varT) 'show 1 0 2 0 End Sub 'AssignToSelectedValuesOf1DVariant Public Sub SelectValuesGreaterThan10() Output.Show "Output" Dim var1D As Variant var1D = Array(1, 20, 3, 40, 5, 60) Output.PrintMessage "Select values from (1,20,3,40,5,60) greater than ten: " + _ McToText(McOpSelect(var1D, McOpGT(var1D, 10))) 'show 20 40 60 End Sub 'SelectValuesGreaterThan10 Public Sub SelectFrom2DVariant() Output.Show "Output" Output.Clear Dim var2D As Variant var2D = Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43)) Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(var2D) Output.PrintMessage "Select 3rd Row: " & _ McToText(McOpSelect(var2D, 2)) 'show 13 23 33 43 Output.PrintMessage "Select 2nd Column: " & _ McToText(McOpSelect(var2D, Empty, 1)) 'show 21 22 23 Output.PrintMessage "Select 2nd and 4th Column from 1st Row: " & _ McToText(McOpSelect(var2D, 0, Array(1, 3))) 'show 21 41 Output.PrintMessage "Select 2nd and 4th Columns: " & vbCrlf & _ McToText(McOpSelect(var2D, Empty, Array(1, 3))) 'show 21 41, 22 42, 23 43 Output.PrintMessage "Select 4th, 2nd and 1st Column from 1st and 3rd Row: " & vbCrlf & _ McToText(McOpSelect(var2D, Array(0, 2), Array(3, 1, 0))) 'show 41 21 11, 43 23 13 Output.PrintMessage "Select values Greater than 32: " & vbCrlf & _ McToText(McOpSelect(var2D, McOpGT(var2D, 32))) 'show 41 42 33 43 'The McOpGT selector in the above statement is a 2-D array that 'selects from both rows and columns, the resulting McOpSelect is a 1-D array. End Sub 'SelectFrom2DVariant Public Sub AssignToSelectedValuesOf2DVariant() Output.Show "Output" Output.Clear Dim var2D As Variant var2D = Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43)) Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(var2D) 'Assign 2, 3, 4 to the 1st column McOpAssignSelected var2D, Array(2, 3, 4), Empty, 0 Output.PrintMessage "** 2,3,4 assigned to 1st column: " & vbCrlf & _ McToText(var2D) 'show 2 21 31 41, 3 22 32 42, 4 23 33 43 'Zero all odd values in the above McOpAssignSelected var2D, 0, McOpNE(McOpAndBits(var2D, 1), 0) 'The McOpNE selector in the above statement is a 2-D array that 'selects elements in both rows and columns for assigment. Note also 'how the associative assignment used the RightOperand scalar value of zero 'repeatedly as necessary to assign to all selected (odd) values. Output.PrintMessage "** All odd values of above array zero'ed: " & vbCrlf & _ McToText(var2D) 'show 2 0 0 0, 0 22 32 42, 4 0 0 0 End Sub 'AssignToSelectedValuesOf2DVariant '***** McObject Examples ******* 'The next set of examples uses McObjects to hold arrays of data. 'The first 5 Sub's are versions of the above that use a McObject to 'hold the array data instead of a Variant. 'Sucessive Sub's get more complex Public Sub SelectFrom1DMcObject() Output.Show "Output" Output.Clear Dim mcobj1D As McObject Set mcobj1D = McObjectTemp(Array(1, 2, 3, 4, 5)) Output.PrintMessage "Select McObject elements 0,4,2 from (1,2,3,4,5) in that order: " & _ McToText(mcobj1D.SelectedMcObject(Array(0, 4, 2))) 'show 1 5 3 Output.PrintMessage "This does the same thing (with an extra internal copy): " & _ McToText(McOpSelect(mcobj1D, Array(0, 4, 2))) 'show 1 5 3 End Sub 'SelectFrom1DMcObject Public Sub AssignToSelectedValuesOf1DMcObject() Output.Show "Output" Dim mcobjT As McObject Set mcobjT = McArrayTemp("INTEGER", 4) 'length-4 1-D array mcobjT.SelectedValues(Array(0, 2)) = Array(1, 2) Output.PrintMessage "Assigned-to McObject array. " + McToText(mcobjT) 'show 1 0 2 0 End Sub 'AssignToSelectedValuesOf1DMcObject Public Sub SelectValuesGreaterThan10FromMcObject() Output.Show "Output" Dim mcobj1D As McObject Set mcobj1D = McObjectTemp(Array(1, 20, 3, 40, 5, 60)) Output.PrintMessage "Select McObject values from (1,20,3,40,5,60) greater than ten: " + _ McToText(mcobj1D.SelectedMcObject(McOpGT(mcobj1D, 10))) 'show 20 40 60 Output.PrintMessage "This does the same thing (with an extra internal copy): " + _ McToText(mcobj1D.SelectedValues(McOpGT(mcobj1D, 10))) 'show 20 40 60 Output.PrintMessage "This also does the same thing with an extra copy: " + _ McToText(McOpSelect(mcobj1D, McOpGT(mcobj1D, 10))) 'show 20 40 60 End Sub 'SelectValuesGreaterThan10FromMcObject Public Sub SelectFrom2DMcObject() Output.Show "Output" Output.Clear Dim mcobj2D As McObject Set mcobj2D = McArrayTemp("INTEGER", Array(3, 4)) '3 rows by 4 columns mcobj2D.OpSelfAssign (Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43))) Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(mcobj2D) Output.PrintMessage "Select McObject 3rd Row: " & _ McToText(mcobj2D.SelectedMcObject(2)) 'show 13 23 33 43 Output.PrintMessage "Select 2nd Column: " & _ McToText(mcobj2D.SelectedMcObject(Empty, 1)) 'show 21 22 23 Output.PrintMessage "Select 2nd and 4th Column from 1st Row: " & _ McToText(mcobj2D.SelectedMcObject(0, Array(1, 3))) 'show 21 41 Output.PrintMessage "Select 2nd and 4th Columns: " & vbCrlf & _ McToText(mcobj2D.SelectedMcObject(Empty, Array(1, 3))) 'show 21 41, 22 42, 23 43 Output.PrintMessage "Select 4th, 2nd and 1st Column from 1st and 3rd Row: " & vbCrlf & _ McToText(mcobj2D.SelectedMcObject(Array(0, 2), Array(3, 1, 0))) 'show 41 21 11, 43 23 13 Output.PrintMessage "Select McObject values Greater than 32: " & vbCrlf & _ McToText(mcobj2D.SelectedMcObject(McOpGT(mcobj2D, 32))) 'show 41 42 33 43 'The McOpGT selector in the above statement is a 2-D array that 'selects from both rows and columns, the resulting SelectedMcObject property is a 1-D array. Output.PrintMessage "This does the same thing (with an extra internal copy): " & vbCrlf & _ McToText(McOpSelect(mcobj2D, McOpGT(mcobj2D, 32))) 'show 41 42 33 43 End Sub 'SelectFrom2DMcObject Public Sub AssignToSelectedValuesOf2DMcObject() Output.Show "Output" Output.Clear Dim mcobj2D As McObject Set mcobj2D = McObjectTemp(Array(Array(11, 21, 31, 41), Array(12, 22, 32, 42), Array(13, 23, 33, 43))) 'Compare the above to the way mcobj2D was filled in SelectFrom2DMcObject, above. 'The results are equivalent except that this McObject will have type "SHORT" (16-bit 'integer), since that is the VB integer type of the Array statements here. The 'McArrayTemp then OpSelfAssign gives you more control (e.g., you could fill all 'rows the same without having to specify them all). Output.PrintMessage "Original 2-D array:" + vbCrlf + McToText(mcobj2D) 'Assign 2, 3, 4 to the 1st column mcobj2D.SelectedMcObject(Empty, 0) = Array(2, 3, 4) 'the following would work too 'McOpAssignSelected mcobj2D, Array(2, 3, 4), Empty, 0 Output.PrintMessage "** 2,3,4 assigned to 1st column: " & vbCrlf & _ McToText(mcobj2D) 'show 2 21 31 41, 3 22 32 42, 4 23 33 43 'Zero all odd values in the above mcobj2D.SelectedMcObject(McOpNE(McOpAndBits(mcobj2D, 1), 0)) = 0 'The McOpNE selector in the above statement is a 2-D array that 'selects elements in both rows and columns for assigment. Note also 'how the associative assignment used the assigning scalar value of zero 'repeatedly as necessary to assign to all selected (odd) values. Output.PrintMessage "** All odd values zero'ed: " & vbCrlf & _ McToText(mcobj2D) 'show 2 0 0 0, 0 22 32 42, 4 0 0 0 End Sub 'AssignToSelectedValuesOf2DMcObject