11-19-2008, 8:06
|
Maen Hasan

Joined on 08-05-2004
Posts 1,876
|
Re: Example of grayscale to 24 bit RGB conversion
|
 
 
|
|
|
Which LEADTOOLS version (v14, v14.5, v15, etc.) are you using?
If you try the same issue by using the following code, do you face the same problem? +---------------+ RasterCodecs.Startup(); RasterCodecs prCodecs = new RasterCodecs(); string prSourceFilePath = @"f:\TempFiles\Winter.jpg"; string prTargetFilePath = @"c:\test.tif"; prCodecs.ThrowExceptionsOnInvalidImages = false;
// Make sure that we can convert this type of file CodecsImageInfo iiCodecsImageInfo = prCodecs.GetInformation(prSourceFilePath, false);
// Unable to convert this format, pop up message if (iiCodecsImageInfo.Format == RasterImageFormat.Unknown) { MessageBox.Show("The file, " + prSourceFilePath + " cannot be converted to an RGB image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
//boInputValid = false; }
// If can convert, create directory and perform conversion if (iiCodecsImageInfo.Format != RasterImageFormat.Unknown) { // Grab the image RasterImage image = prCodecs.Load(prSourceFilePath);
// Change the image to 16-bit grayscale Leadtools.ImageProcessing.GrayscaleCommand grayscaleCmd = new Leadtools.ImageProcessing.GrayscaleCommand(16); grayscaleCmd.Run(image);
// WindowLevelCommand is used to convert from greyscale WindowLevelCommand command = new WindowLevelCommand();
MinMaxBitsCommand minMaxBitsCmd = new MinMaxBitsCommand(); minMaxBitsCmd.Run(image);
MinMaxValuesCommand minMaxValuesCmd = new MinMaxValuesCommand(); minMaxValuesCmd.Run(image);
int lowBit = minMaxBitsCmd.MinimumBit; int highBit = minMaxBitsCmd.MaximumBit;
int size = (1 << (image.HighBit - image.LowBit + 1)); RasterColor[] palette = new RasterColor[size];
int minVal = minMaxValuesCmd.MinimumValue; int maxVal = minMaxValuesCmd.MaximumValue;
for (int x = 0; x < size / 2; x++) palette[x] = new Leadtools.RasterColor(255, 0, 0);
// fill the rest with gray values. for (int x = size / 2; x < size; x++) { int y = (byte)((x - minVal) * 255 / (maxVal - minVal)); palette[x] = new Leadtools.RasterColor(y, y, y); }
command.HighBit = minMaxBitsCmd.MaximumBit; command.LowBit = minMaxBitsCmd.MinimumBit; command.LookupTable = palette; command.Order = Leadtools.RasterByteOrder.Rgb; command.Run(image);
// Save the image in the file path passed to the newly // established raw image file name in TIFF format prCodecs.Options.Save.GrayOutput = false; prCodecs.Save (image, prTargetFilePath, RasterImageFormat.Tif, 0); //use default bits per pixel //prBitsPerPixel);
image.Dispose(); +---------------+
Thanks, Maen Badwan LEADTOOLS Technical Support
|
|
|
|
|
Report
|
|
|
|