InteractiveForegroundSegmenter Class

Segments the source image into foreground and background guided by user provided annotations. The output is a black and white mask where white areas represent the foreground and black areas represent the background.

This class should be used as an effect in the rendering chain, on par with FilterEffect and LensBlurEffect.

The segmenter can be used to provide a mask for one of the other filters or effects, such as BlendFilter or LensBlurEffect.

User input is required for segmentation in form of an AnnotationsSource image, that should contain pixels of at least three colors. Areas painted with ForegroundColor and BackgroundColor are classified as foreground and background areas, while pixels of all other colors are classified as undecided and will be segmented into either foreground or background.

Segmentation is usually an iterative process, where the user keeps improving the AnnotationsSource image until she is happy with the result.

Inheritance Hierarchy

System..::..Object  Nokia.Graphics.Imaging..::..InteractiveForegroundSegmenter

Namespace: Nokia.Graphics.ImagingAssembly: Nokia.Graphics.Imaging (in Nokia.Graphics.Imaging.dll) Version:


public sealed class InteractiveForegroundSegmenter : IClosable, 
	IImageProvider, IImageConsumer, __IInteractiveForegroundSegmenterPublicNonVirtuals
Visual Basic
Public NotInheritable Class InteractiveForegroundSegmenter 
	Implements IClosable, IImageProvider, IImageConsumer, __IInteractiveForegroundSegmenterPublicNonVirtuals
Visual C++
public ref class InteractiveForegroundSegmenter sealed : IClosable, 
	IImageProvider, IImageConsumer, __IInteractiveForegroundSegmenterPublicNonVirtuals



This sample takes CameraCaptureTask result photo and applies a LensBlur with InteractiveForegroundSegmenter effect to it.

async void CaptureTask_Completed(object sender, PhotoResult e)
    const string imageFile = @"Assets\mask.jpg";
    var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

        using (var source = new StreamImageSource(e.ChosenPhoto))
        using (var maskSource = new StorageFileImageSource(file))
        using (var segmentation = new InteractiveForegroundSegmenter(source))
        using (var lensBlurEffect = new LensBlurEffect(source, new LensBlurPredefinedKernel(LensBlurPredefinedKernelShape.Circle, 20)))
            segmentation.AnnotationsSource = maskSource; 
            segmentation.ForegroundColor = Color.FromArgb(255, 255, 255, 255); 
            segmentation.BackgroundColor = Color.FromArgb(255, 255, 238, 51); 
            segmentation.Quality = 0.5;
            lensBlurEffect.KernelMap = segmentation;

            // Create a target where the filtered image will be rendered to
            var target = new WriteableBitmap((int)ImageControl.ActualWidth, (int)ImageControl.ActualHeight);

            // Create a new renderer which outputs WriteableBitmaps
            using (var renderer = new WriteableBitmapRenderer(lensBlurEffect, target))
                // Render the image with the filter(s)
                await renderer.RenderAsync();

                // Set the output image to Image control as a source
                ImageControl.Source = target;
Visual Basic

Visual C++

Last updated 19 June 2014

Back to top