Leadtools.ImageProcessing.Core Namespace : WindowLevelCommand Class |
public class WindowLevelCommand : Leadtools.ImageProcessing.RasterCommand, Leadtools.ImageProcessing.IRasterCommand
'Declaration Public Class WindowLevelCommand Inherits Leadtools.ImageProcessing.RasterCommand Implements Leadtools.ImageProcessing.IRasterCommand
'Usage Dim instance As WindowLevelCommand
public sealed class WindowLevelCommand : Leadtools.ImageProcessing.IRasterCommand
function Leadtools.ImageProcessing.Core.WindowLevelCommand()
public ref class WindowLevelCommand : public Leadtools.ImageProcessing.RasterCommand, Leadtools.ImageProcessing.IRasterCommand
In Silverlight and Windows Phone versions of LEADTOOLS, this image processing command will fail if the image data for the RasterImage object is stored internally using a Silverlight WriteableBitmap object. For more information, refer to Image Processing Command Limitations in Silverlight.
Public Sub WindowLevelCommandExample() Dim codecs As New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg")) ' Prepare the command 'Change the image to 16-bit grayscale Dim graycommand As GrayscaleCommand = New GrayscaleCommand(16) Dim command As WindowLevelCommand = New WindowLevelCommand graycommand.Run(leadImage) Dim minValue As Integer = leadImage.MinValue Dim maxValue As Integer = leadImage.MaxValue Dim minBit As Integer = leadImage.LowBit Dim maxBit As Integer = leadImage.HighBit Dim Size As Integer = (1 << (maxBit - minBit + 1)) Dim LookupTable() As RasterColor ReDim LookupTable(Size - 1) ' fill the first half of the LookupTable with RED. Dim x As Integer For x = 0 To Size \ 2 - 1 LookupTable(x) = New RasterColor(255, 0, 0) Next ' fill the rest with gray values. For x = Size \ 2 To Size - 1 Dim y As Byte = Convert.ToByte((x - minValue) * 255 / (maxValue - minValue)) LookupTable(x) = New RasterColor(y, y, y) Next command.HighBit = maxBit command.LowBit = minBit command.LookupTable = LookupTable command.Order = RasterByteOrder.Bgr command.Run(leadImage) End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void WindowLevelCommandExample() { // Load an image RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Master.jpg")); // Prepare the command int x; byte y; int Size; RasterColor [] LookupTable; //Change the image to 16-bit grayscale GrayscaleCommand graycommand = new GrayscaleCommand(16); MinMaxBitsCommand MinMaxBits = new MinMaxBitsCommand(); MinMaxValuesCommand MinMaxValues = new MinMaxValuesCommand(); WindowLevelCommand command = new WindowLevelCommand(); graycommand.Run(image); MinMaxBits.Run(image); MinMaxValues.Run(image); Size = (1 <<(MinMaxBits.MaximumBit - MinMaxBits.MinimumBit + 1)); LookupTable = new Leadtools.RasterColor[Size]; // fill the first half of the LookupTable with RED. for(x = 0; x < Size / 2; x++) LookupTable[x] = new Leadtools.RasterColor(255, 0, 0); // fill the rest with gray values. for(x = Size / 2; x < Size; x++) { y = (byte)((x - MinMaxValues.MinimumValue) * 255 / (MinMaxValues.MaximumValue - MinMaxValues.MinimumValue)); LookupTable[x] = new Leadtools.RasterColor(y, y, y); } command.HighBit = MinMaxBits.MaximumBit; command.LowBit = MinMaxBits.MinimumBit; command.LookupTable = LookupTable; command.Order = Leadtools.RasterByteOrder.Bgr; command.Run(image); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
function WindowLevelCommandExample() { var codecs = new Leadtools.Codecs.RasterCodecs(); codecs.throwExceptionsOnInvalidImages = true; // Load the image var srcFileName = "Assets\\Image1.cmp"; var processedImage; return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) { return codecs.loadAsync(Leadtools.LeadStreamFactory.create(loadFile)); }).then(function (image) { // Prepare the command with (Leadtools.ImageProcessing.Core) { var x; var y; var Size; var LookupTable = new Array(); //Change the image to 16-bit grayscale var graycommand = new Leadtools.ImageProcessing.GrayscaleCommand(16); var MinMaxBits = new MinMaxBitsCommand(); var MinMaxValues = new MinMaxValuesCommand(); var command = new WindowLevelCommand(); graycommand.run(image); MinMaxBits.run(image); MinMaxValues.run(image); Size = (1 <<(MinMaxBits.maximumBit - MinMaxBits.minimumBit + 1)); // fill the first half of the LookupTable with RED. for(x = 0; x < Size / 2; x++) LookupTable[x] = Leadtools.RasterColorHelper.create(255, 0, 0); // fill the rest with gray values. for(x = Size / 2; x < Size; x++) { y = (x - MinMaxValues.minimumValue) * 255 / (MinMaxValues.maximumValue - MinMaxValues.minimumValue); LookupTable[x] = Leadtools.RasterColorHelper.create(y, y, y); } command.highBit = MinMaxBits.maximumBit; command.lowBit = MinMaxBits.minimumBit; command.lookupTable = LookupTable; command.order = Leadtools.RasterByteOrder.bgr; command.run(image); } }); }
[TestMethod] public async Task WindowLevelCommandExample() { // Load an image RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; // Load the image string srcFileName = @"Assets\Image1.cmp"; StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); // Prepare the command int x; byte y; int Size; RasterColor [] LookupTable; //Change the image to 16-bit grayscale GrayscaleCommand graycommand = new GrayscaleCommand(16); MinMaxBitsCommand MinMaxBits = new MinMaxBitsCommand(); MinMaxValuesCommand MinMaxValues = new MinMaxValuesCommand(); WindowLevelCommand command = new WindowLevelCommand(); graycommand.Run(image); MinMaxBits.Run(image); MinMaxValues.Run(image); Size = (1 <<(MinMaxBits.MaximumBit - MinMaxBits.MinimumBit + 1)); LookupTable = new Leadtools.RasterColor[Size]; // fill the first half of the LookupTable with RED. for(x = 0; x < Size / 2; x++) LookupTable[x] = Leadtools.RasterColorHelper.Create(255, 0, 0); // fill the rest with gray values. for(x = Size / 2; x < Size; x++) { y = (byte)((x - MinMaxValues.MinimumValue) * 255 / (MinMaxValues.MaximumValue - MinMaxValues.MinimumValue)); LookupTable[x] = Leadtools.RasterColorHelper.Create(y, y, y); } command.HighBit = MinMaxBits.MaximumBit; command.LowBit = MinMaxBits.MinimumBit; command.LookupTable = LookupTable; command.Order = Leadtools.RasterByteOrder.Bgr; command.Run(image); }
public void WindowLevelCommandExample(RasterImage image, Stream outStream) { // Prepare the command int x; byte y; int Size; RasterColor[] LookupTable; //Change the image to 16-bit grayscale GrayscaleCommand graycommand = new GrayscaleCommand(16); MinMaxBitsCommand MinMaxBits = new MinMaxBitsCommand(); MinMaxValuesCommand MinMaxValues = new MinMaxValuesCommand(); WindowLevelCommand command = new WindowLevelCommand(); graycommand.Run(image); MinMaxBits.Run(image); MinMaxValues.Run(image); Size = (1 << (MinMaxBits.MaximumBit - MinMaxBits.MinimumBit + 1)); LookupTable = new Leadtools.RasterColor[Size]; // fill the first half of the LookupTable with RED. for (x = 0; x < Size / 2; x++) LookupTable[x] = new Leadtools.RasterColor(255, 0, 0); // fill the rest with gray values. for (x = Size / 2; x < Size; x++) { y = (byte)((x - MinMaxValues.MinimumValue) * 255 / (MinMaxValues.MaximumValue - MinMaxValues.MinimumValue)); LookupTable[x] = new Leadtools.RasterColor(y, y, y); } command.HighBit = MinMaxBits.MaximumBit; command.LowBit = MinMaxBits.MinimumBit; command.LookupTable = LookupTable; command.Order = Leadtools.RasterByteOrder.Bgr; command.Run(image); // Save result image RasterCodecs codecs = new RasterCodecs(); codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24); image.Dispose(); }
Public Sub WindowLevelCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)
' Prepare the command
Dim x As Integer
Dim y As Byte
Dim Size As Integer
Dim LookupTable As RasterColor()
'Change the image to 16-bit grayscale
Dim graycommand As GrayscaleCommand = New GrayscaleCommand(16)
Dim MinMaxBits As MinMaxBitsCommand = New MinMaxBitsCommand()
Dim MinMaxValues As MinMaxValuesCommand = New MinMaxValuesCommand()
Dim command As WindowLevelCommand = New WindowLevelCommand()
graycommand.Run(image)
MinMaxBits.Run(image)
MinMaxValues.Run(image)
Size = (1 << (MinMaxBits.MaximumBit - MinMaxBits.MinimumBit + 1))
LookupTable = New RasterColor(Size - 1) {}
' fill the first half of the LookupTable with RED.
x = 0
Do While x < Size / 2
LookupTable(x) = New RasterColor(255, 0, 0)
x += 1
Loop
' fill the rest with gray values.
x = Size / 2
Do While x < Size
y = CByte((x - MinMaxValues.MinimumValue) * 255 / (MinMaxValues.MaximumValue - MinMaxValues.MinimumValue))
LookupTable(x) = New RasterColor(y, y, y)
x += 1
Loop
command.HighBit = MinMaxBits.MaximumBit
command.LowBit = MinMaxBits.MinimumBit
command.LookupTable = LookupTable
command.Order = RasterByteOrder.Bgr
command.Run(image)
' Save result image
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
image.Dispose()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
WindowLevelCommand Members
Leadtools.ImageProcessing.Core Namespace
Introduction to Image Processing With LEADTOOLS
Grayscale Images
WindowLevelCommand Class
Leadtools.RasterPalette.WindowLevelFillLookupTable(Leadtools.RasterColor[],Leadtools.RasterColor,Leadtools.RasterColor,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,Leadtools.RasterPaletteWindowLevelFlags)
ApplyVoiLookupTableCommand Class
Leadtools.ImageProcessing.Color.ChannelMixerCommand
Leadtools.ImageProcessing.Effects.DeinterlaceCommand
Leadtools.ImageProcessing.Color.DesaturateCommand
Leadtools.ImageProcessing.Effects.EdgeDetectStatisticalCommand
Leadtools.ImageProcessing.Color.LightControlCommand
Leadtools.ImageProcessing.Effects.SmoothEdgesCommand
Leadtools.ImageProcessing.Color.LocalHistogramEqualizeCommand
Leadtools.ImageProcessing.Color.AddWeightedCommand
Leadtools.ImageProcessing.Color.ColorMergeCommand
Leadtools.ImageProcessing.Color.ColorSeparateCommand
Leadtools.ImageProcessing.Color.MultiplyCommand
Leadtools.ImageProcessing.Color.AutoColorLevelCommand
Leadtools.ImageProcessing.Color.ColorLevelCommand
CorrelationCommand Class
Leadtools.ImageProcessing.Color.GrayScaleToDuotoneCommand
Leadtools.ImageProcessing.Color.GrayScaleToMultitoneCommand
Leadtools.ImageProcessing.Effects.RegionHolesRemovalCommand
Leadtools.ImageProcessing.Color.SelectiveColorCommand
Leadtools.ImageProcessing.Effects.SkeletonCommand
Leadtools.ImageProcessing.Color.ChangeHueSaturationIntensityCommand
Leadtools.ImageProcessing.Color.ColorReplaceCommand
Leadtools.ImageProcessing.Color.ColorThresholdCommand
Leadtools.ImageProcessing.Color.MathematicalFunctionCommand
Leadtools.ImageProcessing.Color.SegmentCommand
Leadtools.ImageProcessing.Color.AdaptiveContrastCommand
Leadtools.ImageProcessing.Color.ApplyMathematicalLogicCommand
Leadtools.ImageProcessing.Color.ColorIntensityBalanceCommand
ColorizeGrayCommand Class
Leadtools.ImageProcessing.Color.ContrastBrightnessIntensityCommand
DigitalSubtractCommand Class
Leadtools.ImageProcessing.Color.DynamicBinaryCommand
Leadtools.ImageProcessing.Effects.EdgeDetectEffectCommand
Leadtools.ImageProcessing.SpecialEffects.FunctionalLightCommand
MultiscaleEnhancementCommand Class
SelectDataCommand Class
ShiftDataCommand Class