←Select platform

ShiftDataCommand Class

Summary

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

C#
VB
Java
Objective-C
WinRT C#
C++
public class ShiftDataCommand : RasterCommand 
@interface LTShiftDataCommand : LTRasterCommand 
public class ShiftDataCommand extends RasterCommand 
function Leadtools.ImageProcessing.Core.ShiftDataCommand() 

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.

Example

Run the ShiftDataCommand on an image.

C#
VB
Silverlight C#
Silverlight VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Core; 
 
public void ShiftDataCommandExample() 
{ 
   // Load an image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, @"ImageProcessingDemo\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, Path.Combine(LEAD_VARS.ImagesDir, "ShiftDataResult.bmp"), RasterImageFormat.Bmp, 24); 
 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing.Core 
      Leadtools.Examples.Support.SetLicense() 
 
Public Sub ShiftDataCommandExample() 
   Dim codecs As New RasterCodecs() 
   codecs.ThrowExceptionsOnInvalidImages = True 
 
   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ImageProcessingDemo\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, Path.Combine(LEAD_VARS.ImagesDir, "ShiftDataResult.Bmp"), RasterImageFormat.Bmp, 24) 
 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Examples; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Core; 
 
public void ShiftDataCommandExample(RasterImage image, Stream outStream) 
{ 
   // 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); 
   // Save result image 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24); 
   image.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing.Core 
 
Public Sub ShiftDataCommandExample(ByVal image As RasterImage, ByVal outStream As Stream) 
   ' 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(image) 
   ' Save result image 
   Dim codecs As RasterCodecs = New RasterCodecs() 
   codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24) 
   image.Dispose() 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.ImageProcessing.Core Assembly