←Select platform

SegmentCommand Class

Summary
Divides the image into segments where each segment's pixels have approximately the same color (homogenous color). This command is available in the Imaging and above toolkits.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class SegmentCommand : RasterCommand 
@interface LTSegmentCommand : LTRasterCommand 
public class SegmentCommand 
    extends RasterCommand 
public ref class SegmentCommand : public RasterCommand   
class SegmentCommand(RasterCommand): 
Remarks
  • This command divides the images into segments according to its pixel values . The segment shapes will be arbitrary. Adjacent pixels with approximately the same values are put together into homogenous segments. The command may be performed on the RGB and YUV color spaces.
  • This command supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available only in the Document/Medical toolkits.
  • This command does not support signed data images.
  • This command does not support 32-bit grayscale images.

For more information, refer to Introduction to Image Processing With LEADTOOLS. For more information, refer to Applying Artistic Effects.

Segment Function - Before

Segment Function - Before

Segment Function - After

Segment Function - After

View additional platform support for this Segment function.

Example

Run the SegmentCommand on an image.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Color; 
 
 
public void SegmentCommandExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "sample5.cmp")); 
 
   // Prepare the command 
   SegmentCommand command = new SegmentCommand(); 
   command.Threshold = 20; 
   command.Flags = SegmentCommandFlags.Rgb; 
   //segment the image. 
   command.Run(image); 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.color.*; 
 
 
public void segmentCommandExample() { 
 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.setThrowExceptionsOnInvalidImages(true); 
 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, "sample5.cmp")); 
 
   // Prepare the command 
   SegmentCommand command = new SegmentCommand(); 
   command.setThreshold(20); 
   command.setFlags(SegmentCommandFlags.RGB.getValue()); 
   assertTrue(command.getThreshold() == 20 && command.getFlags() == SegmentCommandFlags.RGB.getValue()); 
   // segment the image. 
   command.run(image); 
   codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"), RasterImageFormat.JPEG, 24); 
 
   assertTrue(new File(combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")).exists()); 
   System.out.println("Command run and file exported to: " + combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")); 
 
} 
Requirements

Target Platforms

See Also

Reference

SegmentCommand Members

Leadtools.ImageProcessing.Color Namespace

Introduction to Image Processing With LEADTOOLS

Applying Artistic Effects

ChangeIntensityCommand Class

GammaCorrectCommand Class

ChangeContrastCommand Class

HistogramContrastCommand Class

StretchIntensityCommand Class

RemapIntensityCommand Class

InvertCommand Class

ChangeHueCommand Class

ChangeSaturationCommand Class

Leadtools.ImageProcessing.FillCommand

HistogramCommand Class

Leadtools.ImageProcessing.Effects.SharpenCommand

Leadtools.ImageProcessing.Effects.MosaicCommand

Leadtools.ImageProcessing.Effects.EmbossCommand

Leadtools.ImageProcessing.Core.MedianCommand

Leadtools.ImageProcessing.Effects.AddNoiseCommand

IntensityDetectCommand Class

Leadtools.ImageProcessing.Effects.SpatialFilterCommand

Leadtools.ImageProcessing.Effects.BinaryFilterCommand

Leadtools.ImageProcessing.Core.MaximumCommand

Leadtools.ImageProcessing.Core.MinimumCommand

Leadtools.ImageProcessing.Effects.OilifyCommand

SolarizeCommand Class

Leadtools.ImageProcessing.Core.WindowLevelCommand

PosterizeCommand Class

ChangeHueSaturationIntensityCommand Class

ColorReplaceCommand Class

ColorThresholdCommand Class

Leadtools.ImageProcessing.Core.DiscreteFourierTransformCommand

Leadtools.ImageProcessing.Effects.DirectionEdgeStatisticalCommand

Leadtools.ImageProcessing.Core.FastFourierTransformCommand

Leadtools.ImageProcessing.Core.FrequencyFilterCommand

Leadtools.ImageProcessing.Core.FrequencyFilterMaskCommand

Leadtools.ImageProcessing.Effects.EffectsUtilities.GetRegionPerimeterLength(Leadtools.RasterImage,Leadtools.RasterRegionXForm)

MathematicalFunctionCommand Class

Leadtools.ImageProcessing.SpecialEffects.RevEffectCommand

Leadtools.ImageProcessing.Core.SubtractBackgroundCommand

Leadtools.ImageProcessing.Effects.UserFilterCommand

Leadtools.ImageProcessing.Effects.HighPassCommand

Leadtools.ImageProcessing.SpecialEffects.BricksTextureCommand

Leadtools.ImageProcessing.SpecialEffects.CanvasCommand

Leadtools.ImageProcessing.SpecialEffects.CloudsCommand

Leadtools.ImageProcessing.SpecialEffects.ColoredBallsCommand

Leadtools.ImageProcessing.SpecialEffects.DiffuseGlowCommand

Leadtools.ImageProcessing.Effects.DisplacementCommand

Leadtools.ImageProcessing.SpecialEffects.FragmentCommand

Leadtools.ImageProcessing.Core.HalfTonePatternCommand

Leadtools.ImageProcessing.Effects.MaskConvolutionCommand

Leadtools.ImageProcessing.SpecialEffects.MosaicTilesCommand

Leadtools.ImageProcessing.Effects.OffsetCommand

Leadtools.ImageProcessing.SpecialEffects.PerspectiveCommand

Leadtools.ImageProcessing.SpecialEffects.PlasmaCommand

Leadtools.ImageProcessing.SpecialEffects.PointillistCommand

Leadtools.ImageProcessing.SpecialEffects.RomanMosaicCommand

Leadtools.ImageProcessing.SpecialEffects.VignetteCommand

Leadtools.ImageProcessing.SpecialEffects.ZigZagCommand

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

Leadtools.ImageProcessing.Color Assembly

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