←Select platform

UserFilterCommand Class

Summary
Filters the image based on a user-defined filter / mask. This command is similar to the spatial and binary filter commands.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public class UserFilterCommand : RasterCommand 
@interface LTUserFilterCommand : LTRasterCommand 
public class UserFilterCommand 
    extends RasterCommand 
public ref class UserFilterCommand : public RasterCommand   
class UserFilterCommand(RasterCommand): 
Remarks
  • With this command you can create a user-defined filter and apply it to the image. The filter has a rectangular form (matrix) where the values are user-defined. It allows the creation of simple customized filters, where each value in matrix is multiplied by the corresponding pixel, and then the specified operation is performed on the results.
  • When the filter is applied to pixels from the edge and you choose the sum operation, the edge rows and columns are duplicated. For example, if the pixel (-1, 5) is needed, the pixel (0, 5) is used instead.
  • 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 32-bit grayscale images.

User Filter Function - Before

User Filter Function - Before

User Filter Function - After

User Filter Function - After

View additional platform support for this User Filter function.

Example

Run the UserFilterCommand on an image, In this example the high pass.filter will be applied using user defined matrix.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Effects; 
 
 
public void UserFilterCommandExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")); 
 
   // Prepare the command 
   int i, j; 
   UserFilterCommand command = new UserFilterCommand(); 
   command.CenterPoint = new LeadPoint(1, 1); 
   command.Divisor = 1; 
   command.Offset = 0; 
   command.Type = UserFilterCommandType.Sum; 
   command.FilterHeight = 3; 
   command.FilterWidth = 3; 
   command.Matrix = new int[9]; 
 
   // Initialize the array with factor used to apply the high pass filter. 
   for (i = 0; i < 3; i++) 
   { 
      for (j = 0; j < 3; j++) 
      { 
         if (j == 1 || i == 1) 
         { 
            if (j == 1 && i == 1) 
               command.Matrix[i * 3 + j] = 5; 
            else 
               command.Matrix[i * 3 + j] = -1; 
         } 
         else 
            command.Matrix[i * 3 + j] = 0; 
      } 
   } 
 
   // Apply the high pass custom filter. 
   command.Run(image); 
 
} 
 
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.effects.UserFilterCommand; 
import leadtools.imageprocessing.effects.UserFilterCommandType; 
 
 
public void userFilterCommandExample() { 
   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, "IMAGE1.CMP")); 
 
   // Prepare the command 
   int i, j; 
   UserFilterCommand command = new UserFilterCommand(); 
   command.setCenterPoint(new LeadPoint(1, 1)); 
   command.setDivisor(1); 
   command.setOffset(0); 
   command.setType(UserFilterCommandType.SUM); 
   command.setFilterHeight(3); 
   command.setFilterWidth(3); 
   command.setMatrix(new int[9]); 
 
   // Initialize the array with factor used to apply the high pass filter. 
   for (i = 0; i < 3; i++) { 
      for (j = 0; j < 3; j++) { 
         if (j == 1 || i == 1) { 
            if (j == 1 && i == 1) 
               command.getMatrix()[i * 3 + j] = 5; 
            else 
               command.getMatrix()[i * 3 + j] = -1; 
         } else 
            command.getMatrix()[i * 3 + j] = 0; 
      } 
   } 
   // Apply the high pass custom filter. 
   int change = command.run(image); 
   assertTrue(change != RasterImageChangedFlags.NONE); 
 
   codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Result.jpg"), RasterImageFormat.JPEG, 24); 
   System.out.println("Command run and image saved to " + combine(LEAD_VARS_IMAGES_DIR, "Result.jpg")); 
} 
Requirements

Target Platforms

See Also

Reference

UserFilterCommand Members

Leadtools.ImageProcessing.Effects Namespace

Leadtools.ImageProcessing.Core.MinimumCommand

Leadtools.ImageProcessing.Core.MaximumCommand

AddNoiseCommand Class

SharpenCommand Class

Leadtools.ImageProcessing.Color.PosterizeCommand

MosaicCommand Class

EmbossCommand Class

AverageCommand Class

Leadtools.ImageProcessing.Core.MedianCommand

Leadtools.ImageProcessing.Color.IntensityDetectCommand

SpatialFilterCommand Class

BinaryFilterCommand Class

OilifyCommand Class

Leadtools.ImageProcessing.Color.SolarizeCommand

Leadtools.ImageProcessing.Core.WindowLevelCommand

Leadtools.ImageProcessing.SpecialEffects.ShadowCommand

Leadtools.ImageProcessing.Color.ChangeHueSaturationIntensityCommand

Leadtools.ImageProcessing.Color.ColorReplaceCommand

Leadtools.ImageProcessing.Color.ColorThresholdCommand

Leadtools.ImageProcessing.Core.DiscreteFourierTransformCommand

DirectionEdgeStatisticalCommand Class

Leadtools.ImageProcessing.Core.FastFourierTransformCommand

Leadtools.ImageProcessing.Core.FrequencyFilterCommand

Leadtools.ImageProcessing.Core.FrequencyFilterMaskCommand

Leadtools.ImageProcessing.Core.FourierTransformDisplayCommand

StatisticsInformationCommand Class

FeretsDiameterCommand Class

ObjectInformationCommand Class

RegionContourPointsCommand Class

GetRegionPerimeterLength Method

Leadtools.ImageProcessing.Color.MathematicalFunctionCommand

Leadtools.ImageProcessing.SpecialEffects.RevEffectCommand

Leadtools.ImageProcessing.Color.SegmentCommand

Leadtools.ImageProcessing.Core.SubtractBackgroundCommand

HighPassCommand Class

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

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