×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    111

    InteractiveForegroundSegmenter behavior when no changes to annotations?

    I have the InteractiveForegroundSegmenter in a pretty large chain of filters and effects in an app I am doing. I took a cue from the samples in the library and am doing a re-render everytime there is an update in the foreground and background annotations made to the photo.

    I've also created some sliders that link to amounts of Blur using the BlurFilter... and many other things like this. Each time the user changes a setting, I re-render the entire image.

    I'm wondering what is the behavior of the InteractiveForegroundSegmenter when you call RenderAsync with it incorporated into the effect chain, but when the annotations are no different from a previous render. Does it recalculate the mask from the annotations? If so, is there a way to stop it from recalculating the mask? The reason I ask is because this effect is extremely processor intensive and makes the entire render process very slow...

    One workaround I am thinking of is to do an intermediate render to a Bitmap and use that for all other effects...

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    511

    Re: InteractiveForegroundSegmenter behavior when no changes to annotations?

    Given that it's rather easy to render the resulting mask into a Bitmap using a BitmapRenderer I would suggest to just try it out and log the duration of the separate runs with and without caching of the mask. I haven't tried it out myself yet but am really curious to see the result of that test.

  3. #3
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    111

    Re: InteractiveForegroundSegmenter behavior when no changes to annotations?

    Finally got around to rewriting it all. There is a significantly noticeable difference in pre-rendering the mask from the InteractiveForegroundSegmenter to a Bitmap and using that with other effects/filters. I don't have hard times but it's enough that I'm keeping it the way it is now.

    This is what I'm doing for anyone interested:

    Code:
    //Code goes into method that updates when drawing annotations
    
    //original image
    using (var source = new BufferImageSource(iBuffer))
    //mask source
    using (var annotationsSource = new BitmapImageSource(annotationsBitmap.AsBitmap()))
    //mask effect
    using (var segmenter = new InteractiveForegroundSegmenter(source))
    using (var renderer = new BitmapRenderer(segmenter, _maskBitmap))
    {
        var foregroundColor = _foregroundBrush.Color;
        var backgroundColor = _backgroundBrush.Color;
        segmenter.ForegroundColor = Windows.UI.Color.FromArgb(
        foregroundColor.A, foregroundColor.R,
        foregroundColor.G, foregroundColor.B);
        segmenter.BackgroundColor = Windows.UI.Color.FromArgb(
        backgroundColor.A, backgroundColor.R,
        backgroundColor.G, backgroundColor.B);
        segmenter.Quality = 0.5;
        segmenter.AnnotationsSource = annotationsSource;
    
        await renderer.RenderAsync();
    }
    You can then use the _maskBitmap as a mask in the Blend filter for another render like so:
    Code:
     
    using (var whiteBackground = new ColorImageSource(new Windows.Foundation.Size(_wBitmap.PixelWidth, _wBitmap.PixelHeight), Windows.UI.Color.FromArgb(255, 255, 255, 255)))
    using (var source = new BufferImageSource(iBuffer))
    using (var maskSource = new BitmapImageSource(_maskBitmap))
    using (var filterEffect = new FilterEffect(whiteBackground))
    using (var renderer = new WriteableBitmapRenderer(filterEffect, _wBitmap))
    {
        var blendFilter = new BlendFilter(source, maskSource, BlendFunction.Normal, 1.0);
        filterEffect.Filters = new IFilter[] {blendFilter};
        renderer.RenderAsync();
    }

Similar Threads

  1. Back key behavior
    By jerry.sun in forum Windows Phone General
    Replies: 2
    Last Post: 2011-11-10, 06:03
  2. Red Key Behavior
    By stavrospapa in forum Symbian
    Replies: 2
    Last Post: 2009-04-14, 11:17
  3. Package behavior
    By abhisheik in forum Mobile Java Games
    Replies: 5
    Last Post: 2006-06-24, 02:10
  4. Strange Behavior
    By akermen in forum Symbian
    Replies: 0
    Last Post: 2006-03-15, 00:28
  5. Behavior of CObexBufObject
    By kaseychen in forum Bluetooth Technology
    Replies: 0
    Last Post: 2006-03-08, 16:13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×