Grayscale Images

LEADTOOLS for .NET provides a number of classes/methods for working with grayscale images. Many of these classes/methods work on either grayscale images or color images. Some of the LEADTOOLS classes/methods however, are designed specifically for use with grayscale images: either creating a grayscale image, getting information about a grayscale image, or window-leveling.

Creating and Working with Grayscale Images

A color image can be converted to a grayscale image using the GrayscaleCommand class. The GrayScaleExtendedCommand class converts an image to a grayscale image, but provides the user the ability to control the calculation of the grayscale pixel value by giving the R, G and B components different "weights" when calculating the grayscale value.

The CreateGrayscale method creates a new grayscale RasterImage from scratch, using the specified parameters and allows the user to control the LOW and HIGH bit of the resulting image.

LEADTOOLS also provides the ConvertToColoredGrayCommand class which converts an image into a grayscale image, while allowing the user to add color effects. This creates an image with an "old-fashioned" look. An 8-bit, 12-bit or 16-bit grayscale image can also be colorized using the ColorizeGrayCommand.

The GrayScaleToDuotoneCommand class converts a grayscale image into a colored one by mixing or replacing the original values of the pixels with new colors.

The GrayScaleToMultitoneCommand converts a grayscale image into a colored one by mixing or replacing the original values of the pixels with one or more new colors.

The CreateAlphaImage method creates a grayscale image from the alpha channel information of an image.

The DesaturateCommand class converts the image to a grayscale level by reducing the saturation of each color to zero. The conversion will not change the color resolution.

The ShiftDataCommand class selects a specified number of bits from an 8-bit, 12-bit or 16-bit grayscale image into a mask and places the mask in a new 8-bit, 12-bit or 16-bit grayscale image. The SelectDataCommand class selects a specified number of bits of an 8-bit, 12-bit 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.

Loading Raw 12-bit and 16-bit Extended Grayscale Images (Document/Medical only)

To load a raw 12-bit and 16-bit extended grayscale image, set the Codecs.InformationEventArgs.Order property to RasterByteOrder.Gray and the CodecsLoadInformationEventArgs.LeastSignificantBitFirst Property accordingly. For signed image data, set the CodecsLoadInformationEventArgs.Signed property to true.

Getting Information about Grayscale Images

LEADTOOLS also provides functions for getting information about grayscale images. The MinMaxBitsCommand class provides information on the minimum and maximum bit set in a 12-bit or 16-bit grayscale image. The MinMaxValuesCommand class gets the minimum and maximum intensity values present in a 12 or 16-bit grayscale image. Please note that support for 12 and 16-bit grayscale images is only available in Document/Medical toolkits. To get a complete histogram of a 12-bit or 16-bit grayscale image, use HistogramCommand.

To determine the kind of grayscale palette associated with an image, if any, use GrayscaleMode.

Window-leveling (Medical only)

Window-leveling is only valid for 12-bit and 16-bit grayscale images, and is used to map grayscale intensities by specifying the bit range and/or a user-defined color map. Two classes/methods are provided for window-leveling. WindowLevel provides "on demand" window-leveling for the paint functions and does not alter the image, and WindowLevelCommand converts the image to a window-leveled 8-bit or 24-bit RGB image. The bit range is passed to the methods through LowBit and HighBit and the user-defined color map is passed through LookupTable. To help set up a bit range and a color map, use MinMaxBitsCommand and MinMaxValuesCommand. MinMaxBitsCommand gets the minimum and maximum bits of the values present in a 12-bit or 16-bit grayscale image. MinMaxValuesCommand gets the minimum and maximum intensity values of the image. WindowLevelFillLookupTable fills the user-allocated LookupTable (LUT) with a color gradient based on the specified values.

LEADTOOLS supports two types of LUTs for 10-16-bit grayscale images (8-bit LUT and 16-bit LUT). Typical grayscale image display and processing is done using an 8-bit LUT. But, you can also use a 16-bit LUT, which offers more precision. Some special video cards and monitors also support display of grayscale images using a 16-bit LUT.

Window-leveling applied with the WindowLevelCommand class can be saved to TIF or DICOM formats without changing the image data. For more information, refer to Saving Window-Leveled Images.

Using the Extended Grayscale Mask

In the Document and Medical toolkits, the COLORREF value can represent a 16-bit grayscale value if pBitmap is a 12-bit or 16-bit grayscale bitmap. To avoid confusion with an RGB value, set the COLORREF_GRAY16 mask (0x04000000). In this case (0x0400YYYY), the lower 16 bits (0xYYYY) of the COLORREF value represent the 16-bit grayscale value. (0x0400FFFF is 16-bit white and 0x04000000 is 16-bit black.) This is not a standard Windows value. Therefore, LEADTOOLS functions will recognize a COLORREF having this format, but Windows functions will not. You can use a COLORREF value of this type in a non-LEADTOOLS function as follows:

const uint COLORREF_GRAY16 = 0x04000000; 
RasterColor color = image.GetPixelColor(x, y); 
uint val = color.ColorRef; 
if ((val & COLORREF_GRAY16) != 0) 
{  // nonstandard colorref value, convert it to a windows COLORREF 
   // get an 8 bit gray value corresponding to the 16 bit gray value 
   byte gray = (byte)((val & 0xFFFF) >> 8); 
   // get a new RasterColor 
   color = new RasterColor(gray, gray, gray); 
} 

Color Halftone and Halftone Images

LEADTOOLS provides a number of commands for working with color images and changing them so they are suitable for printing using halftoning techniques. For more information about these commands, refer to Color Halftone and Halftone Images.

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

LEADTOOLS Imaging, Medical, and Document

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