Click here to Skip to main content
13,299,495 members (57,614 online)
Click here to Skip to main content


57 bookmarked
Posted 21 Jan 2012

Smoothing Kinect Depth Frames in Real-Time

, 24 Jan 2012
Removing noise from the Kinect Depth Frames in real-time using pixel filters and weighted moving average techniques.
using System.Windows;
using System.Threading.Tasks;

namespace KinectDepthSmoothing
    public partial class MainWindow : Window
        private short[] CreateAverageDepthArray(short[] depthArray)
            // This is a method of Weighted Moving Average per pixel coordinate across several frames of depth data.
            // This means that newer frames are linearly weighted heavier than older frames to reduce motion tails,
            // while still having the effect of reducing noise flickering.



            int[] sumDepthArray = new int[depthArray.Length];
            short[] averagedDepthArray = new short[depthArray.Length];

            int Denominator = 0;
            int Count = 1;

            // REMEMBER!!! Queue's are FIFO (first in, first out).  This means that when you iterate
            // over them, you will encounter the oldest frame first.

            // We first create a single array, summing all of the pixels of each frame on a weighted basis
            // and determining the denominator that we will be using later.
            foreach (var item in averageQueue)
                Parallel.For(0, depthArray.Length, i =>
                    sumDepthArray[i] += item[i] * Count;
                Denominator += Count;

            // Once we have summed all of the information on a weighted basis, we can divide each pixel
            // by our calculated denominator to get a weighted average.
            Parallel.For(0, depthArray.Length, i =>
                averagedDepthArray[i] = (short)(sumDepthArray[i] / Denominator);

            return averagedDepthArray;

        private void CheckForDequeue()
            // We will recursively check to make sure we have Dequeued enough frames.
            // This is due to the fact that a user could constantly be changing the UI element
            // that specifies how many frames to use for averaging.
            if (averageQueue.Count > averageFrameCount)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Karl Sanford
Software Developer Open Systems Technologies
United States United States
First learned to program in 1997 on my TI-83 and have been doing it ever since, with a foray into networking and infrastructure.

Mostly a C# junky (Win\Web Forms, WP7.5/8, WPF and MVC), though I have experience with many other technologies and products.

I have also been trying to learn and apply more in the area of AI; focusing on computer vision, natural language processing, and classification.

In my spare time, I love to tinker with electronics and various useless DIY projects.

My brain is a shark... if it stops moving, it will die. I'm always looking to learn more.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 24 Jan 2012
Article Copyright 2012 by Karl Sanford
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid