Leadtools.Windows.Media.Effects Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.02.15
SubtractBackgroundCommandBitmapEffect Class
See Also  Members   Example 
Leadtools.Windows.Media.Effects.Core Namespace : SubtractBackgroundCommandBitmapEffect Class





Removes the background from the image. This command is available in LEADTOOLS Document and Medical Imaging toolkits.

Syntax

Visual Basic (Declaration) 
Public Class SubtractBackgroundCommandBitmapEffect 
   Inherits RasterCommandBitmapEffect
Visual Basic (Usage)Copy Code
Dim instance As SubtractBackgroundCommandBitmapEffect
C# 
public class SubtractBackgroundCommandBitmapEffect : RasterCommandBitmapEffect 
Managed Extensions for C++ 
public __gc class SubtractBackgroundCommandBitmapEffect : public RasterCommandBitmapEffect 
C++/CLI 
public ref class SubtractBackgroundCommandBitmapEffect : public RasterCommandBitmapEffect 
XAML Property Element Usage 

SubtractBackgroundCommandBitmapEffect ...

Example

Run the SubtractBackgroundCommandBitmapEffect on an image.

Visual BasicCopy Code
Public Sub SubtractBackgroundCommandBitmapEffectExample(ByVal element As FrameworkElement)
   Dim effect As SubtractBackgroundCommandBitmapEffect = New SubtractBackgroundCommandBitmapEffect()
   effect.RollingBall = 50
   effect.BrightnessFactor = 100
   effect.ShrinkingSize = SubtractBackgroundCommandBitmapEffectsType.DependOnRollingBallSize
   effect.Flags = SubtractBackgroundCommandBitmapEffectsFlags.BackgroundIsDarker
   element.BitmapEffect = effect

   Dim storyboard As Storyboard = New Storyboard()

   Dim animation1 As Int32Animation = New Int32Animation()
   animation1.From = 0
   animation1.To = 400
   animation1.Duration = New Duration(TimeSpan.Parse("0:0:5"))
   animation1.RepeatBehavior = RepeatBehavior.Forever
   animation1.AutoReverse = True

   storyboard.SetTargetName(animation1, "AnimatedBitmapEffect")
   storyboard.SetTargetProperty(animation1, New PropertyPath(SubtractBackgroundCommandBitmapEffect.BrightnessFactorProperty))
   element.RegisterName("AnimatedBitmapEffect", effect)
   storyboard.Children.Add(animation1)

   storyboard.Begin(element)
End Sub
C#Copy Code
public void SubtractBackgroundCommandBitmapEffectExample(FrameworkElement element) 

   SubtractBackgroundCommandBitmapEffect effect = new SubtractBackgroundCommandBitmapEffect(); 
   effect.RollingBall = 50; 
   effect.BrightnessFactor = 100; 
   effect.ShrinkingSize = SubtractBackgroundCommandBitmapEffectsType.DependOnRollingBallSize; 
   effect.Flags = SubtractBackgroundCommandBitmapEffectsFlags.BackgroundIsDarker; 
   element.BitmapEffect = effect; 
 
   Storyboard storyboard = new Storyboard(); 
 
   Int32Animation animation1 = new Int32Animation(); 
   animation1.From = 0; 
   animation1.To = 400; 
   animation1.Duration = new Duration(TimeSpan.Parse("0:0:5")); 
   animation1.RepeatBehavior = RepeatBehavior.Forever; 
   animation1.AutoReverse = true; 
 
   Storyboard.SetTargetName(animation1, "AnimatedBitmapEffect"); 
   Storyboard.SetTargetProperty(animation1, new PropertyPath(SubtractBackgroundCommandBitmapEffect.BrightnessFactorProperty)); 
   element.RegisterName("AnimatedBitmapEffect", effect); 
   storyboard.Children.Add(animation1); 
 
   storyboard.Begin(element); 
}
XAMLCopy Code
<Page Title="CSAnimateEffect" Height="391" Width="300" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lteffects="clr-namespace:Leadtools.Windows.Media.Effects.Core;assembly=Leadtools.Windows.Media.Effects"> 
  <Grid> 
    <Image Margin="10,10,10,10" HorizontalAlignment="Center" VerticalAlignment="Center" Source="C:\Program Files\LEAD Technologies, Inc\LEADTOOLS 15\Images\slave.jpg"> 
      <Image.BitmapEffect> 
        <lteffects:SubtractBackgroundCommandBitmapEffect x:Name="AnimatedBitmapEffect" RollingBall="50" Flags="SubtractedImage" ShrinkingSize="NoShrinking" /> 
      </Image.BitmapEffect> 
      <Image.Triggers> 
        <EventTrigger RoutedEvent="Image.Loaded"> 
          <BeginStoryboard> 
            <Storyboard> 
              <Int32Animation Storyboard.TargetName="AnimatedBitmapEffect" Storyboard.TargetProperty="BrightnessFactor" From="0" To="400" Duration="0:0:5" RepeatBehavior="Forever" AutoReverse="true" /> 
            </Storyboard> 
          </BeginStoryboard> 
        </EventTrigger> 
      </Image.Triggers> 
    </Image> 
  </Grid> 
</Page>

Remarks

  • This command is useful for correcting non-uniform brightness, especially with medical images and grayscale images.
  • The rolling ball algorithm works as follows:
    1. Consider the image to be a 3-D surface and the z-axis to be the intensity of the image [The component V from the HSV color space].
    2. Roll a 3-D ball beneath the surface so all the points of the ball are under the surface with one or more points of the ball tangent to the surface.
    3. The tangent points to the rolling ball are considered to be the background.
    4. Subtract the background from the original image.
  • The Rolling Ball Radius should be at least as large as the radius of the largest object in the image that is not part of the background to ensure the separation of the background from any objects.
  • A small radius allows the detection of small objects, whereas a larger radius will detect both small and large objects.
  • When subtracting the background, sometimes the result is dim. In such a case you can enhance the brightness after subtracting the background by using the brightness factor value, which functions similar to MultiplyCommandBitmapEffect. Passing 100 for the brightness factor leaves the brightness unchanged.
  • This command does not support signed data images.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Freezable
            System.Windows.Media.Animation.Animatable
               System.Windows.Media.Effects.BitmapEffect
                  Leadtools.Windows.Media.Effects.RasterCommandBitmapEffect
                     Leadtools.Windows.Media.Effects.Core.SubtractBackgroundCommandBitmapEffect

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003

See Also