←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#
Objective-C
C++/CLI
Java
Python
public class ShiftDataCommand : RasterCommand 
@interface LTShiftDataCommand : LTRasterCommand 
public class ShiftDataCommand 
    extends RasterCommand 
public ref class ShiftDataCommand : public RasterCommand   
class ShiftDataCommand(RasterCommand): 
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.

Shift Data Function - Before

Shift Data Function - Before

Shift Data Function - After

Shift Data Function - After

View additional platform support for this Shift Data function.

Example

Run the ShiftDataCommand on an image.

C#
Java
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:\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.assertTrue; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.*; 
 
 
public void shiftDataCommandExample() { 
    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, "Beauty16.jpg")); 
 
    // Prepare the command 
    ShiftDataCommand command = new ShiftDataCommand(); 
    command.setDestinationBitsPerPixel(8); 
    command.setDestinationLowBit(3); 
    command.setSourceLowBit(2); 
    command.setSourceHighBit(6); 
    // Move 5 bits starting from bit 2 into the high bits of the affected image. 
    int change = command.run(image); 
    assertTrue(change != RasterImageChangedFlags.NONE); 
 
    codecs.save(command.getDestinationImage(), combine(LEAD_VARS_IMAGES_DIR, "ShiftDataResult.bmp"), 
            RasterImageFormat.BMP, 24); 
    System.out.println("Command run and image saved to " + combine(LEAD_VARS_IMAGES_DIR, "ShiftDataResult.bmp")); 
} 
Requirements

Target Platforms

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

Leadtools.ImageProcessing.Core Assembly

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