public bool NoGrayConvert { get; set; }
@property (nonatomic, assign) BOOL NoGrayConvert;
public boolean getNoGrayConvert()
public void setNoGrayConvert(boolean value)
NoGrayConvert # get and set (CodecsSaveOptions)
Value | Description |
---|---|
true | To avoid conversion. |
false | To do the conversion (this is the default). |
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.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Core;
using Leadtools.Pdf;
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:\LEADTOOLS23\Resources\Images";
}
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.imageprocessing.core.MinMaxBitsCommand;
public void codecsNoGrayConvertExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
String srcFile = combine(LEAD_VARS_IMAGES_DIR, "DICOM\\image1.dcm"); // Use a DICOM file with less than 16 bit
String dstFile = combine(LEAD_VARS_IMAGES_DIR, "out.jls");
RasterCodecs codecs = new RasterCodecs();
RasterImage image = codecs.load(srcFile);
codecs.getOptions().getSave().setNoGrayConvert(true); // Disable conversion during save //
codecs.save(image, dstFile, RasterImageFormat.JLS_LINE, 0);
assertTrue("File unsuccessfully saved to " + dstFile, (new File(dstFile)).exists());
System.out.printf("File successfully saved to %s%n", dstFile);
codecs.getOptions().getLoad().setNoImageDataConversion(false); // Disable conversion during load //
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);
System.out.println("LowBit = " + command.getMinimumBit() + ", HighBit = " + command.getMaximumBit());
savedImage.dispose();
image.dispose();
codecs.dispose();
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document