public int LRange { get; set; }
LRange # get and set (ConversionLabParameters)
The L component range.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ColorConversion;
using Leadtools.ImageProcessing;
public string outputFile = Path.Combine(LEAD_VARS.ImagesDir, "ColorConversion", "LabToBgr.bmp");
public void ConvertDirectToImageExample()
{
// Start up the ColorConversion.
RasterColorConverterEngine.Startup();
// Input file name
string inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
// Load the input image as BGR
using (RasterCodecs codecs = new RasterCodecs())
using (RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1))
{
// Get the input image buffer array
byte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height];
bgrImage.Access();
bgrImage.GetRow(0, bgrBuffer, 0, bgrImage.BytesPerLine * bgrImage.Height);
bgrImage.Release();
// Create the destination CIELab buffer
byte[] labBuffer = new byte[bgrBuffer.Length];
// Initialize a new Converter object
using (RasterColorConverterEngine colorConverterEngine = new RasterColorConverterEngine())
{
// Conversion parameters
ConversionParameters convParams = new ConversionParameters();
convParams.Method = ConversionMethodFlags.ChangeLab;
// CIELab conversion parameters
ConversionLabParameters labParameters = ConversionLabParameters.Empty;
labParameters.AOffset = 128;
labParameters.ARange = 170;
labParameters.BOffset = 96;
labParameters.BRange = 200;
labParameters.LOffset = 0;
labParameters.LRange = 100;
labParameters.Mask = ConversionLabMaskFlags.AOffset |
ConversionLabMaskFlags.ARange |
ConversionLabMaskFlags.BOffset |
ConversionLabMaskFlags.BRange |
ConversionLabMaskFlags.LOffset |
ConversionLabMaskFlags.LRange;
convParams.LabParameters = labParameters;
// Convert BGR to CIELab buffer using the previous parameters
colorConverterEngine.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Lab, null);
colorConverterEngine.SetParameters(convParams);
colorConverterEngine.Convert(bgrBuffer, // input buffer
0, // offset from the beginning of the source buffer
labBuffer, // output buffer
0, // offset from the beginning of the destination buffer
bgrImage.Width, // pixels width
bgrImage.Height, // pixels height
bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)), // Scanline alignment for input buffer
0); // Scanline alignment for output buffer
colorConverterEngine.Stop();
// To view the image after converison, convert the now CIELab buffer to a BGR image
RasterImage dstImage = new RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);
RasterColorConverterEngine.ConvertDirectToImage(
ConversionColorFormat.Lab,
ConversionColorFormat.Bgr,
labBuffer, // Source buffer
0, // Offset from the beginning of the source buffer
dstImage, // Destination Image
bgrImage.Width, // Pixels width
bgrImage.Height, // Pixels height
0, // Scanline alignment for input buffer
bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))); // Scanline alignment for output buffer
// Save the converted RGB Image
codecs.Save(dstImage, outputFile, RasterImageFormat.Bmp, 24);
}
}
// Shutdown the ColorConversion.
RasterColorConverterEngine.Shutdown();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
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