←Select platform

Threshold Property

Summary

The maximum distance of equality to Color.

Syntax
C#
Objective-C
C++/CLI
Java
Python
public uint Threshold {get; set;} 
@property (nonatomic, assign) NSUInteger threshold; 
public long getThreshold(); 
public void setThreshold( 
   long longValue 
); 
public:  
   property UInt32 Threshold 
   { 
      UInt32 get() 
      void set(UInt32 value) 
   } 
Threshold # get and set (ExObjColorInfo) 

Property Value

The maximum distance of equality to Color. The default value is 0.

Remarks

The distance is calculated in Euclidean RGB color space using the following equation:

Threshold Equation
Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
 
public void ExtractObjectsCommandUseMultiColorsExample() 
{ 
   using (RasterCodecs codecs = new RasterCodecs()) 
   // Load the original image 
   using (RasterImage inputImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "unwarp1.jpg"))) 
   { 
      // Setup the extraction options 
      Tuple<string, RasterColor>[] colors = new Tuple<string, RasterColor>[] 
      { 
         Tuple.Create("DarkGray", new RasterColor(30, 30, 30)), 
         Tuple.Create("DarkGreen", new RasterColor(41, 108, 70)), 
         Tuple.Create("LightRed", new RasterColor(200, 68, 65)) 
      }; 
      ExtractObjectsCommand command = new ExtractObjectsCommand() 
      { 
         ColorInfo = colors 
            .Select(c => new ExObjColorInfo() 
            { 
               Color = c.Item2, 
               Threshold = 50 
            }) 
            .ToArray(), 
         DetectChildren = true, 
         EightConnectivity = true, 
         IgnoreSmallNoise = true, 
         Outline = true, 
         SmallNoiseThreshold = 5, // Filter out noise smaller than 5x5 pixels 
         UseMultiColors = true 
      }; 
 
      // Extract the objects 
      command.Run(inputImage); 
 
      using (ExObjData data = command.Data) 
      { 
         // Put objects into one list for processing all at once 
         List<ExObjObject> objects = new List<ExObjObject>(); 
         foreach (ExObjResult result in data) 
            objects.AddRange(result.Objects); 
 
         // Setup the region options 
         ExObjRegionOptions regionOptions = new ExObjRegionOptions() 
         { 
            Horizontal = true 
         }; 
 
         // Calculate each object's region 
         data.CalculateRegion(objects, regionOptions); 
 
         // Create an output image 
         using (RasterImage outputImage = RasterImage.Create(inputImage.Width, inputImage.Height, 24, inputImage.XResolution, RasterColor.White)) 
         { 
            // Extract each color to a separate image 
            int colorIndex = -1; 
 
            foreach (ExObjResult result in data) 
            { 
               colorIndex++; 
 
               // Fill the output image with white 
               new FillCommand(RasterColor.White).Run(outputImage); 
 
               // Populate the output image with each object's region 
               foreach (ExObjObject @object in result.Objects) 
                  foreach (ExObjSegment segment in @object.RegionHorizontal) 
                  { 
                     // Update the region to the current segment 
                     outputImage.AddRectangleToRegion(null, segment.Bounds, RasterRegionCombineMode.Set); 
 
                     // Fill the region with the current color 
                     new FillCommand(colors[colorIndex].Item2).Run(outputImage); 
                  } 
 
               // Clear the output image's region 
               outputImage.MakeRegionEmpty(); 
 
               // Save the output image 
               codecs.Save(outputImage, Path.Combine(LEAD_VARS.ImagesDir, $"ExtractObjectsMultiColors_{colors[colorIndex].Item1}.png"), RasterImageFormat.Png, 0); 
            } 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.11.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ImageProcessing.Core Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.