Leadtools.ImageProcessing.Effects Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.10
UserFilterCommand Class
See Also  Members   Example 
Leadtools.ImageProcessing.Effects Namespace : UserFilterCommand Class




Filters the image based on a user-defined filter / mask. This command is similar to the spatial and binary filter commands. This command is available in the Raster Pro and above toolkits.

Syntax

Visual Basic (Declaration) 
Public Class UserFilterCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
Visual Basic (Usage)Copy Code
Dim instance As UserFilterCommand
C# 
public class UserFilterCommand : RasterCommand, IRasterCommand  
Managed Extensions for C++ 
public __gc class UserFilterCommand : public RasterCommand, IRasterCommand  
C++/CLI 
public ref class UserFilterCommand : public RasterCommand, IRasterCommand  

Example

Visual BasicCopy Code
ImageProcessing.Effects.UserFilterCommand
   Public Sub UserFilterCommandExample()
      RasterCodecs.Startup()
      Dim codecs As New RasterCodecs()
      codecs.ThrowExceptionsOnInvalidImages = True

      Dim leadImage As RasterImage = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg")

      ' Prepare the command
      Dim i As Integer
      Dim j As Integer
      Dim matrix() As Integer
      ReDim matrix(8)

      Dim command As UserFilterCommand = New UserFilterCommand
      command.CenterPoint = New Point(1, 1)
      command.Divisor = 1
      command.Offset = 0
      command.Type = UserFilterCommandType.Sum
      command.FilterHeight = 3
      command.FilterWidth = 3
      command.Matrix = matrix

      ' Initialize the array with factor used to apply the high pass filter.
      For i = 0 To 2
         For j = 0 To 2
            If (j = 1 Or i = 1) Then
               If (j = 1 And i = 1) Then
                  command.Matrix(i * 3 + j) = 5
               Else
                  command.Matrix(i * 3 + j) = -1
               End If
            Else
               command.Matrix(i * 3 + j) = 0
            End If
         Next
      Next

      ' Apply the high pass custom filter.
      command.Run(leadImage)
      codecs.Save(leadImage, "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Result.jpg", RasterImageFormat.Jpeg, 24)

      RasterCodecs.Shutdown()
   End Sub
C#Copy Code
ImageProcessing.Effects.UserFilterCommand 
      public void UserFilterCommandExample() 
      { 
         // Load an image 
         RasterCodecs.Startup(); 
         RasterCodecs codecs = new RasterCodecs(); 
         codecs.ThrowExceptionsOnInvalidImages = true; 
 
         RasterImage image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Master.jpg"); 
 
         // Prepare the command 
         int i, j; 
         UserFilterCommand command = new UserFilterCommand(); 
         command.CenterPoint = new Point(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); 
 
         RasterCodecs.Shutdown(); 
      }

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.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Effects.UserFilterCommand

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also