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



Displaces image pixels horizontally and vertically according to the values of the displacement map image.

Syntax

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

Example

Run the DisplacementCommand on an image and applies the Displace Map filter.

Visual BasicCopy Code
Public Sub DisplacementCommandExample()
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True

   Dim leadImage As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Master.jpg")

   ' Prepare the command
   Dim fillColor As RasterColor = New RasterColor(0, 0, 0)
   Dim command As DisplacementCommand = New DisplacementCommand

   command.DisplacementMapImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "slave.jpg")
   command.HorizontalFactor = 17
   command.VerticalFactor = 24
   command.FillColor = fillColor
   command.Flags = DisplacementCommandFlags.NoChange Or DisplacementCommandFlags.StretchToFit
   command.Run(leadImage)
   codecs.Save(leadImage, LeadtoolsExamples.Common.ImagesPath.Path + "Result.jpg", RasterImageFormat.Jpeg, 24)

   RasterCodecs.Shutdown()
End Sub
C#Copy Code
public void DisplacementCommandExample() 

   // Load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Master.jpg"); 
 
   // Prepare the command 
   RasterColor fillColor = new RasterColor(0, 0, 0); 
   DisplacementCommand command = new DisplacementCommand(); 
 
   command.DisplacementMapImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "slave.jpg"); 
   command.HorizontalFactor = 17; 
   command.VerticalFactor = 24; 
   command.FillColor = fillColor; 
   command.Flags = DisplacementCommandFlags.NoChange | DisplacementCommandFlags.StretchToFit; 
   command.Run (image); 
 
   RasterCodecs.Shutdown(); 
}

Remarks

  • This command shifts image pixels according to the values of the displacement map. Red values in the displacement map shift the original pixels horizontally. Green values in the displacement map shift the original values vertically. Blue values are ignored. A displacement map value of 128 means not to shift anything. A displacement map value of 0 means to shift pixels the complete vertical or horizontal percentage, to the left or down. A displacement map value of 255 means to shift pixels the complete vertical or horizontal percentage, to the right or up.
  • Displacement maps modify the geometry of the object. As a result, pixel shifts and forms may be added to the image, and the image may be warped or distorted.
  • As an example, if you use the following image:

    And you were to use the following image as your displacement map:

    And you were to call DisplacementCommand using the following settings:
    ParameterValue
    HorizontalFactor17
    VerticalFactor24
    FillColorna
    FlagsDisplacementCommandFlags.NoChange | DisplacementCommandFlags.StretchToFit

    The following figure results:
  • 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 Removing Noise.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Effects.DisplacementCommand

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