Indicates whether object extraction should be performed for multiple colors instead of bitonal.
public bool UseMultiColors {get; set;} Public Property UseMultiColors() As BooleanGetSet
public:property bool UseMultiColors{bool get()void set(bool value)}
true to extract objects for each specified entry in ColorInfo; otherwise, false for bitonal extraction. The default value is false.
The colors can be configured using ColorInfo.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Core;public void ExtractObjectsCommandUseMultiColorsExample(){using (RasterCodecs codecs = new RasterCodecs())// Load the original imageusing (RasterImage inputImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "unwarp1.jpg"))){// Setup the extraction optionsTuple<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 pixelsUseMultiColors = true};// Extract the objectscommand.Run(inputImage);using (ExObjData data = command.Data){// Put objects into one list for processing all at onceList<ExObjObject> objects = new List<ExObjObject>();foreach (ExObjResult result in data)objects.AddRange(result.Objects);// Setup the region optionsExObjRegionOptions regionOptions = new ExObjRegionOptions(){Horizontal = true};// Calculate each object's regiondata.CalculateRegion(objects, regionOptions);// Create an output imageusing (RasterImage outputImage = RasterImage.Create(inputImage.Width, inputImage.Height, 24, inputImage.XResolution, RasterColor.White)){// Extract each color to a separate imageint colorIndex = -1;foreach (ExObjResult result in data){colorIndex++;// Fill the output image with whitenew FillCommand(RasterColor.White).Run(outputImage);// Populate the output image with each object's regionforeach (ExObjObject @object in result.Objects)foreach (ExObjSegment segment in @object.RegionHorizontal){// Update the region to the current segmentoutputImage.AddRectangleToRegion(null, segment.Bounds, RasterRegionCombineMode.Set);// Fill the region with the current colornew FillCommand(colors[colorIndex].Item2).Run(outputImage);}// Clear the output image's regionoutputImage.MakeRegionEmpty();// Save the output imagecodecs.Save(outputImage, Path.Combine(LEAD_VARS.ImagesDir, $"ExtractObjectsMultiColors_{colors[colorIndex].Item1}.png"), RasterImageFormat.Png, 0);}}}}}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CorePublic Sub ExtractObjectsCommandUseMultiColorsExample()Using codecs As New RasterCodecs()' Load the original imageUsing inputImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "unwarp1.jpg"))' Setup the extraction optionsDim colors As Tuple(Of String, RasterColor)() = New Tuple(Of 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))}Dim command As New ExtractObjectsCommand() With {.ColorInfo = colors.[Select](Function(c) New ExObjColorInfo() With {.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 objectscommand.Run(inputImage)Using data As ExObjData = command.Data' Put objects into one list for processing all at onceDim objects As New List(Of ExObjObject)()For Each result As ExObjResult In dataobjects.AddRange(result.Objects)Next' Setup the region optionsDim regionOptions As New ExObjRegionOptions() With {.Horizontal = True}' Calculate each object's regiondata.CalculateRegion(objects, regionOptions)' Create an output imageUsing outputImage As RasterImage = RasterImage.Create(inputImage.Width, inputImage.Height, 24, inputImage.XResolution, RasterColor.White)' Extract each color to a separate imageDim colorIndex As Integer = -1For Each result As ExObjResult In datacolorIndex += 1' Fill the output image with whiteCall New FillCommand(RasterColor.White).Run(outputImage)' Populate the output image with each object's regionFor Each [object] As ExObjObject In result.ObjectsFor Each segment As ExObjSegment In [object].RegionHorizontal' Update the region to the current segmentoutputImage.AddRectangleToRegion(Nothing, segment.Bounds, RasterRegionCombineMode.[Set])' Fill the region with the current colorCall New FillCommand(colors(colorIndex).Item2).Run(outputImage)NextNext' Clear the output image's regionoutputImage.MakeRegionEmpty()' Save the output imagecodecs.Save(outputImage, Path.Combine(LEAD_VARS.ImagesDir, $"ExtractObjectsMultiColors_{colors(colorIndex).Item1}.png"), RasterImageFormat.Png, 0)NextEnd UsingEnd UsingEnd UsingEnd UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
