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



Selects a specific number of bits from an 8, 12 or 16-bit grayscale image to create a mask and places the mask in a new 8, 12 or 16-bit grayscale image. This command is available in the Medical toolkits.

Syntax

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

Example

Run the ShiftDataCommand on an image.

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

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

   ' Prepare the command
   Dim command As ShiftDataCommand = New ShiftDataCommand
   command.DestinationBitsPerPixel = 8
   command.DestinationLowBit = 3
   command.SourceLowBit = 2
   command.SourceHighBit = 6
   ' Move 5 bits starting from bit 2 into the high bits of the affected image.
   command.Run(leadImage)
   codecs.Save(command.DestinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "ShiftDataResult.Bmp", RasterImageFormat.Bmp, 24)

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

   // Load an image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Beauty16.jpg"); 
 
   // Prepare the command 
   ShiftDataCommand command = new ShiftDataCommand(); 
   command.DestinationBitsPerPixel = 8; 
   command.DestinationLowBit = 3; 
   command.SourceLowBit = 2; 
   command.SourceHighBit = 6; 
   // Move 5 bits starting from bit 2 into the high bits of the affected image. 
   command.Run(image); 
   codecs.Save(command.DestinationImage, LeadtoolsExamples.Common.ImagesPath.Path + "ShiftDataResult.bmp", RasterImageFormat.Bmp, 24); 
 
   RasterCodecs.Shutdown(); 
}

Remarks

  • This command is used as a visualization aid. You can select certain bits of the supported type image and show the variances of that image under conditions that you define.
  • You can use this command for other purposes than visualization. For example, let's say you loaded a 16-bit file that has the pixels in Motorola format (where the high and low bytes are swapped). You can swap the high and low 8 bits for each pixel by calling this command twice and OR-ing the results.
  • The destination image should not be allocated when calling this command. You should free the allocated image before calling this command. When the command returns successfully the destination image will be an 8, 12 or 16-bit grayscale.
  • For 8, 12 and 16-bit grayscale images, the source low bit can range from 0 to 7, 0 to 11, and 0 to 15 respectively. However if this value exceeded the range then the command will not return an error, and the destination image will be a pure black image.
  • The source high bit must be greater than or equal to source low bit. The command will return an invalid parameter error if SourceHighBit < SourceLowBit.
  • The destination low bit can range from 0 to destination bits per pixel - 1. If you pass greater values for destination low bit, the command will not return an error, but destination image will become a pure black image.
  • The following example shows you how to treat a 16-bit grayscale image:
    • In a16-bit grayscale image, the bits are ordered as b15 b14 b13 ... b2 b1 b0. You can choose the bit from where to start moving the bits.
    • For example, if the mask starts at the fourth bit (b3), with a length equal to 6 bits, the destination starting position is 4 and we want to create an 8-bit destination image:
    • SourceLowBit = 3, SourceHighBit = 8, DestinationLowBit = 4, DestinationBitsPerPixel = 8.
    • Source image:
    • -----------------
    • b15 b14 b13 b12 b11 b10 b9 |b8 b7 b6 b5 b4 b3| b2 b1 b0
    • -----------------
    • 0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 1
    • Destination image (DestinationImage):
    • -----------
    • |b7 b6 b5 b4| b3 b2 b1 b0
    • -----------
    • 0 0 1 1 0 0 0 0
    • You can notice that b7 and b8 of Source Image are truncated in the DestinationImage since there is no space for them.
  • This command supports 8, 12 and 16-bit grayscale bitmaps only. Support for 12 and 16-bit grayscale images are available only in the Document/Medical toolkits. It also can process the whole image or a region of the image. If an image has a region, the effect is applied only to the region.
  • This command does not support 32-bit grayscale images.
For more information, refer to Correcting Colors.
For more information, refer to Grayscale Images.

Inheritance Hierarchy

System.Object
   Leadtools.ImageProcessing.RasterCommand
      Leadtools.ImageProcessing.Core.ShiftDataCommand

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