Threshold Classes
Hello
I've wrote an automation that applies 5 threshold classes to an image however when I try to delete the classes I find I can't. I recorded the code below
Dim image1 With Application.DocumentCommands.ActiveImage(NewMacro) .Run(image1) End With With Measure.ThresholdToolCommands.Thresholds(NewMacro) .AllowOverlap = False .Interpretation = eInterpretation.Mono .Classes = New System.Collections.Generic.List(Of SegmentationClass) .Classes.Add(New SegmentationClass("Class ",System.Drawing.Color.Blue,New Double(){205R,255R})) .Run(image1) End With
This code doesn't remove the other classes it just adds another. When I recorded I deleted each class in sequence but it doesn't seem to have recorded this. Also when I produce the classes I label them Class 1, Class2 etc but when they appear in the measurements table I find I'm upto Class 35 and this doesn't reset on restarting Premier. Are there any low level commands to reset the threshold classes .
Regards
David
Best Answer
-
Hello David,That Beta version is quite old, it could explain the differences in macro behaviour. I will send you a link to the latest Beta directly.Yuri0
Answers
-
David,Classes are defined in different commands. The command you use is related to the threshold segmentation. If you want to set classes for existing measurements you should use Options command. The command that resets classes is recorded from UI clicking the Reset button in the Classes group of measurements ribbon tab.
Public Function ResetClasses() As SimpleScript ResetClasses = New SimpleScript Dim doc1 With Application.DocumentCommands.Active(ResetClasses) .Run(doc1) End With With Measure.MeasurementsCommands.Options(ResetClasses) .Classes = New System.Collections.Generic.List(Of MMClassDescr) .Classes.Add(New MMClassDescr("Class 1",System.Drawing.Color.Blue,ePointShape.LargeTarget90)) .ActiveClass = 1 .Run(doc1) End With End Function
Yuri0 -
Hello Yuri
It doesn't work, I run it and there are still 5 divided classes on the threshold tool
Regards
David
0 -
David,The macro I posted is not for the threshold tool, that's for Classes in the measurements.You can reset classes in the Threshold tool clicking the Reset button in Classes group. If you execute the macro, as you shown on top, the threshold tool will use only 1 class (Single class threshold).Depending on you count options (Reset existing data or Preserve existing data) the threshold class will be set to active class or (in case of Preserve) appended to the Classes in measurements.Yuri0
-
Hello Yuri
Just tried the reset classes button which works when you manually press it. However when I record the code to use in my automation the recorded code doesn't work it just adds another class and sends the classes already present all over the place. This is the recorded code I got.
Dim image1 With Application.DocumentCommands.ActiveImage(Nothing) .Run(image1) End With With Measure.ThresholdToolCommands.Thresholds(Nothing) .AllowOverlap = False .Interpretation = eInterpretation.Mono .Classes = New System.Collections.Generic.List(Of SegmentationClass) .Classes.Add(New SegmentationClass("Class 1",System.Drawing.Color.Aqua,New Double(){0R,128R})) .Run(image1) End With
Regards
David
0 -
David,What is you final goal? Does it involve Count? Please try recording a macro that includes Count operation.The macro below I just recorded and playing it back it counts class "MyClass". Please test it (as it is) and let me know if it works properly.
Public Function CountMyClass() As SimpleScript CountMyClass = New SimpleScript Dim doc1 With Application.DocumentCommands.Active(CountMyClass) .Run(doc1) End With With Measure.MeasurementsCommands.Options(CountMyClass) .Classes = New System.Collections.Generic.List(Of MMClassDescr) .Classes.Add(New MMClassDescr("MyClass",System.Drawing.Color.Blue,ePointShape.LargeTarget90)) .ActiveClass = 1 .Run(doc1) End With With Measure.MeasurementsCommands.Options(CountMyClass) .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpManual .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation .Run(doc1) End With With Measure.ThresholdToolCommands.Thresholds(CountMyClass) .AllowOverlap = False .Interpretation = eInterpretation.Mono .Classes = New System.Collections.Generic.List(Of SegmentationClass) .Classes.Add(New SegmentationClass("MyClass",System.Drawing.Color.Blue,New Double(){0R,128R})) .Run(doc1) End With With Measure.MeasurementsCommands.ExecuteCount(CountMyClass) .Run(doc1) End With End Function
Yuri0 -
Hello Yuri
Still doesn't work it just adds another class called MyClass and counts all the classes together. I can't attach my code in a file or put it in this window as its too big. I can put it on my server for download if that's OK
Regards
David
0 -
David,Do you have Count Option "Reset existing data " or "Preserve existing data"?What version of Premier are you using?Yuri0
-
Hello Yuri
I have Reset existing data selected and I'm using Premier 3D 64bit Version 9.1.27 Build 5340
Regards
David
0 -
Hello Yuri
Updating to the latest version worked.
Regards
David
0
Categories
- All Categories
- 961 Image-Pro v9 and higher
- 9 Image-Pro FAQs
- 18 Image-Pro Download & Install
- 448 Image-Pro General Discussions
- 486 Image-Pro Automation (Macros, Apps, Reports)
- 20 AutoQuant Deconvolution
- 2 AutoQuant Download & Install
- 18 AutoQuant General Discussions
- 195 Image-Pro Plus v7 and lower
- 3 Image-Pro Plus Download & Install
- 106 Image-Pro Plus General Discussions
- 86 Image-Pro Plus Automation with Macros
- 19 Legacy Products
- 16 Image-Pro Premier 3D General Discussions
- 26 Image-Pro Insight General Discussions