←Select platform

NoGrayConvert Property

Summary
Indicates whether to avoid converting image data when saving 12- or 16-bit grayscale images.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public bool NoGrayConvert { get; set; } 
@property (nonatomic, assign) BOOL NoGrayConvert; 
public boolean getNoGrayConvert() 
public void setNoGrayConvert(boolean value) 
public: 
property bool NoGrayConvert { 
   bool get(); 
   void set (    bool ); 
} 
NoGrayConvert # get and set (CodecsSaveOptions) 

Property Value

Value Description
true To avoid conversion.
false To do the conversion (this is the default).
Remarks

The default value for this property is false (the image data is converted).

You can set this property to true to disable the image data conversion.

Images with 12- or 16-bit image data sometimes require extra information (LowBit, HighBit and/or LUT) for proper display.

Some formats (DICOM, TIF) can store this extra data. Consequently, we can save files in these formats without changing the image data. The image is guaranteed to look the same after loading the output.

Other formats (e.g.: JLS, J2K) cannot store this extra information. In such cases, LEADTOOLS converts the grayscale images to the full 16-bit range to ensure the image will look good once you load the output.

In some situations, this extra information can be stored through other means, or can be recovered using image processing (MinMaxBitsCommand or MinMaxValuesCommand). In these cases, it might be better to avoid the conversion to the full 12- or 16-bit range. The NoGrayConvert property can be used to disable this conversion.

Keep in mind that if you set NoGrayConvert to true, the output file might not display properly (i.e. could look washed out or totally black) unless you restore the window leveling information (RasterImage.LowBit, RasterImage.HighBit, the LUT, etc.) that ensures proper display of the original image. See the Window-Leveling section from Introduction to Image Processing With LEADTOOLS for more details.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
 
public void Save10BitJls() 
{ 
   string srcFile = Path.Combine(LEAD_VARS.ImagesDir, @"DICOM\FMX18", @"de10.dcm"); /* Use a DICOM file with less than 16 bit image data */ 
   string dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"out.jls"); 
 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      using (RasterImage image = codecs.Load(srcFile)) 
      { 
         codecs.Options.Save.NoGrayConvert = true; /* Disable conversion during save */ 
         codecs.Save(image, dstFile, RasterImageFormat.Jls, 0); 
         codecs.Options.Load.NoImageDataConversion = true; /* Disable conversion during load */ 
         using (RasterImage savedImage = codecs.Load(dstFile)) 
         { 
            /* The image data should be the same as before the save. But the image might look all black, because savedImage.LowBit and savedImage.HighBit are not set properly. 
               The MinMaxBitsCommand might detect the LowBit/HighBit values that would improve the image output. 
             */ 
            MinMaxBitsCommand command = new MinMaxBitsCommand(); 
            command.Run(savedImage); 
            Debug.WriteLine($"LowBit = {command.MinimumBit}, HighBit = {command.MaximumBit}"); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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