←Select platform

BorderRemoveCommand Constructor(BorderRemoveCommandFlags,BorderRemoveBorderFlags,int,int,int)

Summary
Initializes a new BorderRemoveCommand class object with explicit parameters.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (instancetype)initWithFlags:(LTBorderRemoveCommandFlags)flags border:(LTBorderRemoveBorderFlags)border percent:(NSInteger)percent whiteNoiseLength:(NSInteger)whiteNoiseLength variance:(NSInteger)variance NS_DESIGNATED_INITIALIZER; 
public BorderRemoveCommand( 
   int flags,  
   int border,  
   int percent,  
   int whiteNoiseLength,  
   int variance 
) 
__init__(self,flags,border,percent,whiteNoiseLength,variance) # Overloaded constructor 

Parameters

flags
Flag that determines the behavior of the border removal process.

border
Flag that indicates which border to remove.

percent
Percent of the image dimension in which the border will be found. For most images, use 20. For example, if an image is 200 pixels wide, Percent is set to 20 and Border is set to BorderRemoveBorderFlags.Left, then the left border will be found in the area between the left edge of the image and a line 40 pixels from the left edge. If the border is closer to the edge of the image, use a smaller value. If the border is farther from the edge, use a larger value.

whiteNoiseLength
Amount of white noise tolerated when determining the border. The units are in pixels. Values of 0 to 10 are sufficient for most images.

variance
Amount of variance tolerated in the border. If the border varies significantly in thickness, you should use a higher value for Variance. Range is 0 to 10.

Example

Run the BorderRemoveCommand on an image.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
 
public void BorderRemoveConstructorExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif")); 
 
   // Prepare the command 
   BorderRemoveCommand command = new BorderRemoveCommand(BorderRemoveCommandFlags.UseVariance | BorderRemoveCommandFlags.CallBackRegion, BorderRemoveBorderFlags.All, 20, 9, 3); 
   command.BorderRemove += new EventHandler<BorderRemoveCommandEventArgs>(command_BorderRemove_S2); 
   command.Run(image); 
 
} 
 
private void command_BorderRemove_S2(object sender, BorderRemoveCommandEventArgs e) 
{ 
   BorderRemoveCommandEventArgs ee = new BorderRemoveCommandEventArgs(e.Image, e.Region, BorderRemoveBorderFlags.All, e.BoundingRectangle); 
   e.Status = RemoveStatus.NoRemove; 
 
   if (e.Region != null) 
   { 
      e.Image.SetRegion(null, e.Region, RasterRegionCombineMode.Set); 
      InvertCommand command = new InvertCommand(); 
      command.Run(e.Image); 
      e.Image.MakeRegionEmpty(); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.beans.EventHandler; 
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.core.*; 
import leadtools.imageprocessing.color.*; 
 
 
public void borderRemoveConstructorExample() { 
 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.setThrowExceptionsOnInvalidImages(true); 
 
   RasterImage image = codecs.load(combine(LEAD_VARS_IMAGES_DIR, 
         "clean.tif"), 1, CodecsLoadByteOrder.BGR, 1, 1); 
 
   // Prepare the command 
   BorderRemoveCommand command = new BorderRemoveCommand( 
         BorderRemoveCommandFlags.USE_VARIANCE.getValue() | BorderRemoveCommandFlags.CALLBACK_REGION.getValue(), 
         BorderRemoveBorderFlags.ALL.getValue(), 20, 9, 3); 
   command.addBorderRemoveCommandListener(commandBorderRemoveS2); 
   command.run(image); 
 
   System.out.println("Command run and image saved to " + combine(LEAD_VARS_IMAGES_DIR, "clean.tif")); 
   assertTrue(new File(combine(LEAD_VARS_IMAGES_DIR, "clean.tif")).exists()); 
 
} 
 
BorderRemoveCommandListener commandBorderRemoveS2 = new BorderRemoveCommandListener() { 
 
   @Override 
   public void onBorderRemoveEvent(BorderRemoveCommandEvent e) { 
      e.setStatus(RemoveStatus.NO_REMOVE); 
      if (e.getRegion() != null) { 
         e.getImage().setRegion(null, e.getRegion(), RasterRegionCombineMode.SET); 
         InvertCommand command = new InvertCommand(); 
         command.run(e.getImage()); 
         e.getImage().makeRegionEmpty(); 
      } 
   } 
}; 
Requirements

Target Platforms

Help Version 23.0.2024.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.