←Select platform

SelectDataCommand Class

Summary

Selects a specific number of bits of an 8, 12 or 16-bit grayscale image and puts them into a mask, then colors the image depending on the mask. This can show image variances depending on user-defined conditions. This command is available in the Medical toolkits.

Syntax
C#
VB
C++
public class SelectDataCommand : RasterCommand 
Public Class SelectDataCommand  
   Inherits RasterCommand 
public ref class SelectDataCommand : public 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.
  • For 8, 12 and 16-bit grayscale image, the source low bit can range from 0 to 7, 11, and 15 respectively. However if this value exceeded the range then the method will not return an error, and the DestinationImage will be a pure black image.
  • For 8, 12 and 16-bit grayscale image, the source high bit can range from source low bit to 7, 11, and 15 respectively. No error will be returned if source high bit is greater than 7, 11 or 15. The command will return an invalid parameter error if source high bit < source low bit.
  • The command will first construct a mask from bits source low bit through source high bit. For each pixel, the pixel value will be combined with the mask using a bitwise 'and' operation. The result will be shifted to the right by source low bit. This result will be compared with the threshold: if the value is greater than or equal to the threshold, the output pixel's color is changed using the Color property or the color parameter if you are using the appropriate Constructor. If the result is less than the threshold, the output is set to 0.
  • The following example shows you how to treat a 16-bit grayscale image:
    • In a 16-bit grayscale image, the bits are ordered as b15 b14 b13 ... b2 b1 b0.
    • For SourceLowBit = 3, SourceHighBit = 8, Threshold = 16 and Color = new RasterColor(0, 255, 0)
    • In Source image (SourceImage)

    • 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
  • In our case, the mask is 010011 in base 2 (19 in decimal). Since 19 >= 16, the destination pixel will be colored using the Color property (or the color parameter of the Constructor). The output pixel will be:
    • if Combine = false: Color = new RasterColor(0,255,0)
    • if Combine = true: we take the high byte of the source pixel, which is 01101110 in base 2 (0x6E), and then the value is AND-ed with each component of the color. So the output pixel will be RGB(0x00 & 0x6E, 0xFF & 0x6E, 0x00 & 0x6E) which is RGB(0x00, 0x6E, 0x00).
  • Let us consider another case: the source pixel is 0110111000011101 the mask value is 000011 in base 2(3 in decimal). Since 3 > 16, the destination pixel will be:
    • if the combine value = false: Color = new RasterColor(0,0,0)
    • if the combine value = true: The high byte of the source pixel will bet set for the RGB, that is RGB(0x6E, 0x6E, 0x6E).
  • 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 SelectDataCommand on an image.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Core; 
 
public void SelectDataCommandExample() 
{ 
   // 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 
   SelectDataCommand command = new SelectDataCommand(); 
   command.Color = new RasterColor(233, 10, 77); 
   command.Combine = true; 
   command.SourceLowBit = 2; 
   command.SourceHighBit = 6; 
   command.Threshold = 25; 
 
   command.Run(image); 
   codecs.Save(command.DestinationImage, Path.Combine(LEAD_VARS.ImagesDir, "SelectDataResult.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 
 
Public Sub SelectDataCommandExample() 
   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 SelectDataCommand = New SelectDataCommand 
   command.Color = New RasterColor(233, 10, 77) 
   command.Combine = True 
   command.SourceLowBit = 2 
   command.SourceHighBit = 6 
   command.Threshold = 25 
 
   command.Run(leadImage) 
   codecs.Save(command.DestinationImage, Path.Combine(LEAD_VARS.ImagesDir, "SelectDataResult.bmp"), RasterImageFormat.Bmp, 24) 
 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

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

Leadtools.ImageProcessing.Core Assembly