Click or drag to resize

RegionsOperatorsmRgnRelativeSize Method

Region size as an integral multiple of the size of the smallest objects.

Namespace:  MediaCy.IQL.Operators
Assembly:  MediaCy.IQL.Operators (in MediaCy.IQL.Operators.dll) Version: 3.1.0.0
Syntax
VB
<ExtensionAttribute>
Public Shared Function mRgnRelativeSize ( 
	regions As McRegions
) As McMeasure

Parameters

regions
Type: MediaCy.IQL.FeaturesMcRegions

Return Value

Type: McMeasure

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type McRegions. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
In its default configuration, the mRgnRelativeSize measurement iteratively computes the mean area of areas smaller than 190% of the prior loop mean area until no more regions are excluded; this results in a "small Wobject mean area". The algorithm then labels objects with area less than 175% of that mean with a value of one and labels larger objects with the rounded integer value of (object area / small object mean). If all real-world items in the image are of approximately the same size and touching items to not overlap too much (e.g. BBs scattered on a table), then the result of the above algorithm is a measure of clustering, where a cluster is defined as the number of touching items that resolve into one detected object. It is possible to change the behavior of the mRgnRelativeSize measurement by assigning to mRgnRelativeSize.UserData. And some ancilary results from the last computation of mRgnRelativeSize may be obtained by accessing mRgnRelativeSize.UserData. The rules are pretty rigid: On assignment to mRgnRelativeSize.UserData an array of Objects in pairs may be assigned. Each pair consists of a key string followed by a value. Two key strings are currently supported: The "RefSizeOverride" key string may be associated with a Double value greater than zero giving an area in calibrated units^2 to substitute for the "small object mean"; a RefSizeOverride value of zero restores use of the small object mean as the reference size. The "FloatResults" key string may be associated with a Boolean value which if True causes the mRgnRelativeSize results to be the actual ratio of the object area to the reference area (which may be either the "small object mean" or the RefSizeOverride value. On access to the mRgnRelativeSize.UserData property, a 2-D 2 by 8 array of Object is returned. Each of the 8 Object pairs is a string followed by a value variant. The strings come from the mcobjRelativeSizeUserDataKeys module, where each associated value is documented. The pairs pairs report information in this order: "LastReferenceSize", Double "LastSmallSizeCount", Integer "LastNonSmallSizeCount", Integer "LastSmallSizeArea", Double "LastNonSmallSizeArea", Double "RefSizeOverride", Double (zero if no override) "FloatResults", Boolean "RawUserData", Object (which will usually be Nothing)
Examples
VB
Here is an set of access functions with a test macro that shows how to
set the RefSizeOverride and FloatResults as well as how to access the
supplemental resuls.  The utility functions are shown first with the
test macro at the end.  The macro will need references to MediaCy.Addins.Measurements.dll
and to MediaCy.IQL.Features.dll
Private Function luGetMcMMData() As MediaCy.Addins.Measurements.McMMData
Dim imgA As McImage = ThisApplication.ActiveImage
If imgA Is Nothing Then Return Nothing
Dim mmData As MediaCy.Addins.Measurements.McMMData = imgA.MeasurementsData
Return mmData
End Function 'luGetMcMMData
Private Function luGetMeasuresMcRegions() As MediaCy.IQL.Features.McRegions
Dim mmData As MediaCy.Addins.Measurements.McMMData = luGetMcMMData
If ( mmData Is Nothing OrElse mmData.Count = 0 ) Then Return Nothing
Dim mcregionsMeas As MediaCy.IQL.Features.McRegions = mmData.SubFeature(0).GetFeatures
Return mcregionsMeas
End Function 'luGetMeasuresMcRegions
Private Function luGetRelativeSizeMcMeasure() As MediaCy.IQL.Features.IMcMeasure
Dim mcregionsMeas As MediaCy.IQL.Features.McRegions = luGetMeasuresMcRegions()
If (mcregionsMeas Is Nothing) Then Return Nothing
Dim measRelSize As MediaCy.IQL.Features.IMcMeasure = mcregionsMeas.mRgnRelativeSize
Return measRelSize
End Function 'luGetRelativeSizeMcMeasure
Private Function luSetRelativeSizeReferenceOverride( ByVal dRefSizeOverride As Double, Optional ByVal bFloatResults As Boolean = False) As Boolean
Dim measRelSize As MediaCy.IQL.Features.IMcMeasure = luGetRelativeSizeMcMeasure()
If measRelSize Is Nothing Then Return False
Dim arrayRefSizeOverride(0 To 3) As Object
arrayRefSizeOverride(0) = "RefSizeOverride"
arrayRefSizeOverride(1) = dRefSizeOverride
arrayRefSizeOverride(2) = "FloatResults"
arrayRefSizeOverride(3) = bFloatResults
measRelSize.UserData = arrayRefSizeOverride
measRelSize.Compute
luGetMcMMData.ShowMeasurements(MediaCy.Addins.Measurements.McMeasurements.enumShowMeasFlags.smfShowAll) 'update results display
Return True
End Function 'luSetRelativeSizeReferenceOverride
Private Function luGetRelativeSizeUserDataReport() As String
Dim measRelSize As MediaCy.IQL.Features.IMcMeasure = luGetRelativeSizeMcMeasure()
If measRelSize Is Nothing Then Return ""
Dim arUD As Object = measRelSize.UserData
Dim nPairs As Integer = arUD.GetLength(0)
Dim nResults As Integer = arUD.GetLength(1)
If nPairs<>2 OrElse nResults<>8 Then MsgBox("Bad nPairs or nResults")
Dim strR As String = "*** mRgnRelativeSize.UserData values ****" + vbCrLf
strR = strR + "nPairs " + CStr(nPairs) + "  nResults " + CStr(nResults) + vbCrLf
Dim iR As Integer
For iR = 0 To nResults-1
Dim strKey As String = CStr(arUD(0,iR))
Dim varValue As Object = arUD(1,iR)
Dim strValue As String
If varValue Is Nothing Then
strValue = "Nothing"
Else
strValue = CStr( varValue)
End If
strR = strR + "Key: " + strKey + " Value: " + strValue + vbCrLf
Next 'iR
Return strR
End Function 'luGetRelativeSizeUserDataReport
Public Sub TestRelativeSizeOverride
Dim dNewRefSize As Double = CDbl( InputBox( "Reference Size Override: ", "RelativeSize Reference Size Override", "0.0"))
Dim mbrFloatResults As Integer = MsgBox( "Float Relative Size Results?", vbOkCancel, "Make RelativeSize Float")
Dim bFloatResults As Boolean = (mbrFloatResults = vbOK)
Dim bOK As Boolean = luSetRelativeSizeReferenceOverride( dNewRefSize, bFloatResults)
Dim strReport As String
If bOK Then
strReport = luGetRelativeSizeUserDataReport
Else
strReport = "No ActiveImage or no measurements"
End If
ThisApplication.Output.Clear
ThisApplication.Output.PrintMessage( strReport)
End Sub 'TestRelativeSizeOverride
Here is the result output from running TestRelativeSizeOverride on the
Spots.tif sample image with Reference Size Override set to 0.0 and
clicking OK for the "Float Relative Size Results?" question.
*** mRgnRelativeSize.UserData values ****
nPairs 2  nResults 8
Key: LastReferenceSize Value: 278.384615384615
Key: LastSmallSizeCount Value: 39
Key: LastNonSmallSizeCount Value: 3
Key: LastSmallSizeArea Value: 10857
Key: LastNonSmallSizeArea Value: 2921
Key: RefSizeOverride Value: 0
Key: FloatResults Value: True
Key: RawUserData Value: Nothing
See Also