Change CLASSIFICATION of FEATURES with CODE . . .
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.
In reality I determine the DISTANCE of each FEATURE CENTER XY from a REFERENCE CENTER XY (perhaps the UPPER LEFT IMAGE CORNER) in the image. I would like an efficient way to classify each FEATURE as being CLASS 1 NEAR (< 1 mm DISTANCE) or CLASS 2 FAR (>= 1 mm DISTANCE) from the REFERENCE XY.
I have a ROUTINE that does this individually but I would like to do this as a group.
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)'refreshYuri
Yes, your solution is correct, you can use sf.SfClass for feature classification very efficiently.
.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))
'UPDATE THE CLASSIFICATION FOR THIS FEATURE TO 1
'UPDATE THE CLASSIFICATION FOR THIS FEATURE TO 2
Public Function UpdateClassification(MyFeatureName As String, MyClassification As Integer)
Dim image1, doc1
Dim var1 = MyFeatureName, meas1
.SelectionFlag = McMeasurements.enumMMSelTypes.mcmmsfAddWithReset
.ActiveClass = MyClassification