LEADTOOLS WPF and Silverlight (Leadtools.Windows.Media.Effects assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
WindowLevelEffect Class
See Also  Members  
Leadtools.Windows.Media.Effects Namespace : WindowLevelEffect Class



Fills and applies window leveling on the specified image. Supported in Silverlight

Object Model

WindowLevelEffect Class

Syntax

Visual Basic (Declaration) 
Public Class WindowLevelEffect 
   Inherits System.Windows.Media.Effects.ShaderEffect
   Implements IAnimatable 
Visual Basic (Usage)Copy Code
Dim instance As WindowLevelEffect
C# 
public class WindowLevelEffect : System.Windows.Media.Effects.ShaderEffect, IAnimatable  
C++/CLI 
public ref class WindowLevelEffect : public System.Windows.Media.Effects.ShaderEffect, IAnimatable  

Example

Visual BasicCopy Code
Class WindowLevelEffectExampleWindow
      Inherits Window
      Public Sub New()
         Dim sp As New StackPanel()
         Content = sp
         Dim theViewer As New RasterImageViewer()

         theViewer.HorizontalAlignment = HorizontalAlignment.Center
         theViewer.VerticalAlignment = VerticalAlignment.Top
         theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left
         theViewer.ImageVerticalAlignment = VerticalAlignment.Top

         sp.Children.Add(theViewer)

         ' Load an image into the viewer
         Using codecs As New RasterCodecs()
            theViewer.Image = codecs.Load(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Image3.dcm"))
         End Using

         ' Create the sliders
         Dim tb As New TextBlock()
         tb.HorizontalAlignment = HorizontalAlignment.Center
         tb.Text = "Window Width:"
         sp.Children.Add(tb)

         Dim windowWidthSlider As New Slider()
         windowWidthSlider.Minimum = 0.0
         windowWidthSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1)
         windowWidthSlider.Width = 400
         windowWidthSlider.Orientation = Orientation.Horizontal
         windowWidthSlider.IsSnapToTickEnabled = True
         windowWidthSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight
         windowWidthSlider.TickFrequency = 0.1
         windowWidthSlider.AutoToolTipPrecision = 2
         windowWidthSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight

         sp.Children.Add(windowWidthSlider)

         tb = New TextBlock()
         tb.HorizontalAlignment = HorizontalAlignment.Center
         tb.Text = "Window Center:"
         sp.Children.Add(tb)

         Dim windowCenterSlider As New Slider()
         windowCenterSlider.Minimum = 0.0
         windowCenterSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1)
         windowCenterSlider.Width = 400
         windowCenterSlider.Orientation = Orientation.Horizontal
         windowCenterSlider.IsSnapToTickEnabled = True
         windowCenterSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight
         windowCenterSlider.TickFrequency = 0.1
         windowCenterSlider.AutoToolTipPrecision = 2
         windowCenterSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight

         sp.Children.Add(windowCenterSlider)

         ' Setup the effect
         Dim effect As New WindowLevelEffect()

         ' Set the texture
         effect.FillGrayTexture(theViewer.Image)
         effect.Start = Colors.Black
         effect.End = Colors.White
         effect.CurveType = CurveType.Linear
         effect.Factor = 0.0

         effect.WindowWidth = Math.Pow(2, theViewer.Image.MaxValue - theViewer.Image.MinValue)
         effect.WindowCenter = effect.WindowWidth / 2

         theViewer.ImageEffect = effect

         ' Bind the properties
         Dim bind As New Binding()
         bind.Source = effect
         bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
         bind.Path = New PropertyPath("WindowWidth")
         windowWidthSlider.SetBinding(Slider.ValueProperty, bind)

         bind = New Binding()
         bind.Source = effect
         bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
         bind.Path = New PropertyPath("WindowCenter")
         windowCenterSlider.SetBinding(Slider.ValueProperty, bind)

         Title = "Using WindowLevelEffect"
      End Sub
   End Class

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
class WindowLevelEffectExampleWindow : Window
   {
      public WindowLevelEffectExampleWindow()
      {
         StackPanel sp = new StackPanel();
         Content = sp;
         RasterImageViewer theViewer = new RasterImageViewer();

         theViewer.HorizontalAlignment = HorizontalAlignment.Center;
         theViewer.VerticalAlignment = VerticalAlignment.Top;
         theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left;
         theViewer.ImageVerticalAlignment = VerticalAlignment.Top;

         sp.Children.Add(theViewer);

         // Load an image into the viewer
         using(RasterCodecs codecs = new RasterCodecs())
         {
            theViewer.Image = codecs.Load(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Image3.dcm"));
         }

         // Create the sliders
         TextBlock tb = new TextBlock();
         tb.HorizontalAlignment = HorizontalAlignment.Center;
         tb.Text = "Window Width:";
         sp.Children.Add(tb);

         Slider windowWidthSlider = new Slider();
         windowWidthSlider.Minimum = 0.0;
         windowWidthSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1);
         windowWidthSlider.Width = 400;
         windowWidthSlider.Orientation = Orientation.Horizontal;
         windowWidthSlider.IsSnapToTickEnabled = true;
         windowWidthSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight;
         windowWidthSlider.TickFrequency = 0.1;
         windowWidthSlider.AutoToolTipPrecision = 2;
         windowWidthSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight;

         sp.Children.Add(windowWidthSlider);

         tb = new TextBlock();
         tb.HorizontalAlignment = HorizontalAlignment.Center;
         tb.Text = "Window Center:";
         sp.Children.Add(tb);

         Slider windowCenterSlider = new Slider();
         windowCenterSlider.Minimum = 0.0;
         windowCenterSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1);
         windowCenterSlider.Width = 400;
         windowCenterSlider.Orientation = Orientation.Horizontal;
         windowCenterSlider.IsSnapToTickEnabled = true;
         windowCenterSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight;
         windowCenterSlider.TickFrequency = 0.1;
         windowCenterSlider.AutoToolTipPrecision = 2;
         windowCenterSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight;

         sp.Children.Add(windowCenterSlider);

         // Setup the effect
         WindowLevelEffect effect = new WindowLevelEffect();

         // Set the texture
         effect.FillGrayTexture(theViewer.Image);
         effect.Start = Colors.Black;
         effect.End = Colors.White;
         effect.CurveType = CurveType.Linear;
         effect.Factor = 0.0;

         effect.WindowWidth = Math.Pow(2, theViewer.Image.MaxValue - theViewer.Image.MinValue);
         effect.WindowCenter = effect.WindowWidth / 2;

         theViewer.ImageEffect = effect;

         // Bind the properties
         Binding bind = new Binding();
         bind.Source = effect;
         bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
         bind.Path = new PropertyPath("WindowWidth");
         windowWidthSlider.SetBinding(Slider.ValueProperty, bind);

         bind = new Binding();
         bind.Source = effect;
         bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
         bind.Path = new PropertyPath("WindowCenter");
         windowCenterSlider.SetBinding(Slider.ValueProperty, bind);

         Title = "Using WindowLevelEffect";
      }
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
class WindowLevelEffectExampleWindow : UserControl
{
   public WindowLevelEffectExampleWindow()
   {
      StackPanel sp = new StackPanel();
      Content = sp;
      RasterImageViewer theViewer = new RasterImageViewer();

      theViewer.HorizontalAlignment = HorizontalAlignment.Center;
      theViewer.VerticalAlignment = VerticalAlignment.Top;
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left;
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top;

      sp.Children.Add(theViewer);

      // Load an image into the viewer
      //using(RasterCodecs codecs = new RasterCodecs())
      {
         RasterCodecs codecs = new RasterCodecs();
         theViewer.Image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Image3.dcm");
      }

      // Create the sliders
      TextBlock tb = new TextBlock();
      tb.HorizontalAlignment = HorizontalAlignment.Center;
      tb.Text = "Window Width:";
      sp.Children.Add(tb);

      Slider windowWidthSlider = new Slider();
      windowWidthSlider.Minimum = 0.0;
      windowWidthSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1);
      windowWidthSlider.Width = 400;
      windowWidthSlider.Orientation = Orientation.Horizontal;

      sp.Children.Add(windowWidthSlider);

      tb = new TextBlock();
      tb.HorizontalAlignment = HorizontalAlignment.Center;
      tb.Text = "Window Center:";
      sp.Children.Add(tb);

      Slider windowCenterSlider = new Slider();
      windowCenterSlider.Minimum = 0.0;
      windowCenterSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1);
      windowCenterSlider.Width = 400;
      windowCenterSlider.Orientation = Orientation.Horizontal;

      sp.Children.Add(windowCenterSlider);

      // Setup the effect
      WindowLevelEffect effect = new WindowLevelEffect();

      // Set the texture
      effect.FillGrayTexture(theViewer.Image);
      effect.Start = Colors.Black;
      effect.End = Colors.White;
      effect.CurveType = CurveType.Linear;
      effect.Factor = 0.0;

      effect.WindowWidth = Math.Pow(2, theViewer.Image.MaxValue - theViewer.Image.MinValue);
      effect.WindowCenter = effect.WindowWidth / 2;

      theViewer.ImageEffect = effect;

      // Bind the properties
      Binding bind = new Binding();
      bind.Source = effect;
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default;
      bind.Path = new PropertyPath("WindowWidth");
      windowWidthSlider.SetBinding(Slider.ValueProperty, bind);

      bind = new Binding();
      bind.Source = effect;
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default;
      bind.Path = new PropertyPath("WindowCenter");
      windowCenterSlider.SetBinding(Slider.ValueProperty, bind);
   }
}
SilverlightVBCopy Code
Class WindowLevelEffectExampleWindow
   Inherits UserControl
   Public Sub New()
      Dim sp As New StackPanel()
      Content = sp
      Dim theViewer As New RasterImageViewer()

      theViewer.HorizontalAlignment = HorizontalAlignment.Center
      theViewer.VerticalAlignment = VerticalAlignment.Top
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top

      sp.Children.Add(theViewer)

      ' Load an image into the viewer
      Dim codecs As New RasterCodecs()
      theViewer.Image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Image3.dcm")

      ' Create the sliders
      Dim tb As New TextBlock()
      tb.HorizontalAlignment = HorizontalAlignment.Center
      tb.Text = "Window Width:"
      sp.Children.Add(tb)

      Dim windowWidthSlider As New Slider()
      windowWidthSlider.Minimum = 0.0
      windowWidthSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1)
      windowWidthSlider.Width = 400
      windowWidthSlider.Orientation = Orientation.Horizontal

      sp.Children.Add(windowWidthSlider)

      tb = New TextBlock()
      tb.HorizontalAlignment = HorizontalAlignment.Center
      tb.Text = "Window Center:"
      sp.Children.Add(tb)

      Dim windowCenterSlider As New Slider()
      windowCenterSlider.Minimum = 0.0
      windowCenterSlider.Maximum = Math.Pow(2, theViewer.Image.BitsPerPixel - 1)
      windowCenterSlider.Width = 400
      windowCenterSlider.Orientation = Orientation.Horizontal

      sp.Children.Add(windowCenterSlider)

      ' Setup the effect
      Dim effect As New WindowLevelEffect()

      ' Set the texture
      effect.FillGrayTexture(theViewer.Image)
      effect.Start = Colors.Black
      effect.End = Colors.White
      effect.CurveType = CurveType.Linear
      effect.Factor = 0.0

      effect.WindowWidth = Math.Pow(2, theViewer.Image.MaxValue - theViewer.Image.MinValue)
      effect.WindowCenter = effect.WindowWidth / 2

      theViewer.ImageEffect = effect

      ' Bind the properties
      Dim bind As New Binding()
      bind.Source = effect
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default
      bind.Path = New PropertyPath("WindowWidth")
      windowWidthSlider.SetBinding(Slider.ValueProperty, bind)

      bind = New Binding()
      bind.Source = effect
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default
      bind.Path = New PropertyPath("WindowCenter")
      windowCenterSlider.SetBinding(Slider.ValueProperty, bind)
   End Sub
End Class

Remarks

Provides "on demand" window-leveling as an effect and does not alter the image data.

To learn more about window-leveling, refer to RasterImage.WindowLevel, RasterImage.WindowLevelExt, WindowLevelCommand and Leadtools.ImageProcessing.Core.WindowLevelExtCommand.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Freezable
            System.Windows.Media.Animation.Animatable
               System.Windows.Media.Effects.Effect
                  System.Windows.Media.Effects.ShaderEffect
                     Leadtools.Windows.Media.Effects.WindowLevelEffect

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also