Change CLASSIFICATION of FEATURES with CODE . . .
2021-03-11-183551
All --
I have an image that has approximately 100 features in it that have been found with a THRESHOLD and a COUNT.
After the COUNT all of the features are in CLASS 1
I create CLASS 2 and I would like to reclassify some of the features with CODE based on the position of each feature in the image.
I have code that will perform this operation but it does it one by one and it takes about 20 seconds to work through the 100 features in the image.
I have a ROUTINE that does this individually but I would like to do this as a group.
Thanks.
-- Matt
0
Best Answers
-
Hi Matt,
The most efficient way to classify objects by distance to a point is to use the distance map: create distance map (3D Filters: Distance map) from the point of interest (place a black dot on white image) and transfer object outlines to the map (using Features Manager or copy map to the original image using Calc operations) and measure the Intensity Mean, which will correspond to the distance:
then you can classify the object by Intensity Mean. This method will work fast even when you have hundreds of thousands of objects.
If you have only 100 objects, the direct distance calculation can also work fast (milliseconds) if you use code like this:For Each sf As McMMSubFeature In ThisApplication.ActiveImage.MeasurementsData.SubFeatures Dim x as Double=sf.Value(eMeasures.RgnCentroidX) Dim y as Double=sf.Value(eMeasures.RgnCentroidY) Dim dist As Double=System.Math.Sqrt(x*x+y*y)'distance from the top-left corner sf.SfClass=1+dist/100'classify by distance Next ThisApplication.ActiveImage.MeasurementsData.BeginUpdateBlock(False)'refresh
Yuri0 -
Hi Matt,
Yes, your solution is correct, you can use sf.SfClass for feature classification very efficiently.
Yuri0
Answers
.Classes = New System.Collections.Generic.List(Of MMClassDescr)
.Classes.Add(New MMClassDescr("CENTER",System.Drawing.Color.FromArgb(CType(255, Byte),CType(0, Byte),CType(0, Byte)),ePointShape.LargeTarget90))
.Classes.Add(New MMClassDescr("RING",System.Drawing.Color.FromArgb(CType(255, Byte),CType(255, Byte),CType(0, Byte)),ePointShape.LargeTarget45))
.Run(doc1)
End With
Then
'UPDATE THE CLASSIFICATION FOR THIS FEATURE TO 1
UpdateClassification(MyDataTable.SubFeature(MyN).Name, 1)
Else
'UPDATE THE CLASSIFICATION FOR THIS FEATURE TO 2
UpdateClassification(MyDataTable.SubFeature(MyN).Name, 2)
End If
Public Function UpdateClassification(MyFeatureName As String, MyClassification As Integer)
Dim image1, doc1
Dim var1 = MyFeatureName, meas1
With Application.DocumentCommands.ActiveImage(Nothing)
.Run(image1)
End With
With Application.DocumentCommands.Define(Nothing)
.Run(image1, doc1)
End With
With Measure.MeasurementsCommands.Define(Nothing)
.Run(var1, meas1)
End With
With Measure.MeasurementsCommands.Selection(Nothing)
.SelectionFlag = McMeasurements.enumMMSelTypes.mcmmsfAddWithReset
.Run(doc1, meas1)
End With
With Measure.MeasurementsCommands.Options(Nothing)
.ActiveClass = MyClassification
.Run(doc1)
End With
With Measure.MeasurementsCommands.ApplyClass(Nothing)
.Run(doc1)
End With
End Function