RegionsOperatorsmaRgnCalipers Method |
![]() |
Namespace: MediaCy.IQL.Operators
<ExtensionAttribute> Public Shared Function maRgnCalipers ( regions As McRegions ) As McMeasureAngles
'This is ArrayMeasurementsSamples.bas Option Explicit Public Sub Access2DMeasurements() 'The example image below with the given thresholding yields 3 region features Images.Open Path & "Images\BoneBig.jpg" ActiveImage.Aoi.SetBox -1, 10, 10, 100, 100 With ActiveImage.RegionFeatures .Threshold.IntensityRange = Array(128, 255) ' set some Threshold .Threshold.Execute ' find some regions and rid small ones Dim lMinPixelArea As Long lMinPixelArea = 200 .CleanUpBordersAndNoise ActiveImage.Aoi, mcrbNoBorder, lMinPixelArea Dim nRows As Long, nValues As Integer nRows = .Count ' number of rows = number of regions detected If nRows = 0 Then MsgBox "You didn't find any regions." Exit Sub End If .maRgnDiameters.NumAngles = 8 ' 32 values by Default, but we want fewer for this example nValues = .maRgnDiameters.NumAngles 'This many diameters are extracted per row ' the "ma" results are described to be a 2-D array of nRows x nValues ' .maRgnDiameters.Compute 'Calling Compute is not necessary, since it is done automatically 'Below are 4 ways to access this measurement result Output.Show "Output" Output.Clear 'Here's one way of accessing the Value property with a feature selector (using straight VB) Output.PrintMessage "Example 1. Straight VB, accessing maRgnDiameters.Value using a selector" Dim iRegion As Long, iVal As Long, strT As String For iRegion = 0 To nRows - 1 ReDim oneFeatureArray(0 To nValues - 1) As Double oneFeatureArray = .maRgnDiameters.value(iRegion) strT = "Row" & Str(iRegion) & " diameters:" For iVal = 0 To nValues - 1 strT = strT & Str(oneFeatureArray(iVal)) Next iVal Output.PrintMessage strT Next iRegion 'Here's another way of accessing the Value property as a 2-D array (using straight VB) Output.PrintMessage vbCrLf & "Example 2. Straight VB, accessing maRgnDiameters.Value whole, as a 2-D array" 'Note that VB 2-D array declarations and indexing are backwards from C/C++ ReDim allFeature2DArray(0 To nValues - 1, 0 To nRows - 1) As Double allFeature2DArray = .maRgnDiameters.value For iRegion = 0 To nRows - 1 strT = "Row" & Str(iRegion) & " diameters:" For iVal = 0 To nValues - 1 'Note that VB 2-D array indexing is backwards from C/C++ strT = strT & Str(allFeature2DArray(iVal, iRegion)) Next iVal Output.PrintMessage strT Next iRegion 'Here's an easier way (using McToText for the print-out and a Value property selector) Output.PrintMessage vbCrLf & "Example 3. McToText, accessing maRgnDiameters.Value using a selector" For iRegion = 0 To nRows - 1 ReDim oneFeatureArray(0 To nValues - 1) As Double oneFeatureArray = .maRgnDiameters.value(iRegion) Output.PrintMessage "Row" & Str(iRegion) & " diameters: " & McToText(oneFeatureArray) Next iRegion 'Here's an even easier way (using McOMGlobal vector operations to select one "Row" of values at a time) Output.PrintMessage vbCrLf & "Example 4. Using McOMGlobal, accessing maRgnDiameters.ValueMcObject" Dim mcobjValue As McObject Set mcobjValue = .maRgnDiameters.ValueMcObject For iRegion = 0 To nRows - 1 Output.PrintMessage "Row" & Str(iRegion) & " diameters: " & McToText(mcobjValue.SelectedMcObject(iRegion)) Next iRegion ' In general, .maRgnDiameters.value(iRegion) returns a Variant holding an array of length ' .maRgnDiameters.NumAngles for the iRegion'th region, while .maRgnDiameters.value returns ' a Variant holding a 2-D array with .Count "Rows" each holding .maRgnDiameters.NumAngles ' elements (of type Double). The .maRgnDiameters.ValueMcObject is just a McObject (of ' type mcobjTypeREAL) holding this 2-D array. End With 'ActiveImage.RegionFeatures ActiveWindow.Close End Sub 'Access2DMeasurements