# Question about noise point reduction

**URL:** https://discourse.processing.org/t/question-about-noise-point-reduction/3306
**Category:** Coding Questions
**Created:** [September 6, 2018, 3:53am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306 "2018-09-06T03:53:58Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 6, 2018, 3:53am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/1 "2018-09-06T03:53:58Z")

</div>

Hi, I’m working on a project with Kinect V2 and have some questions…  
I take the video from the depth camera of Kinect V2 and there are so many noise points!! I only need black and white color image. The idea is make the color black when something is in a certain depth. And all the others will be white. Is there any way that can delete or reduce the noise points?  
36%20AM|612x500

 ![36%20AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/77500ceee9568940700ae8ec2e30ba865c9e0113.jpeg)

This is the code, I’m using the example by Daniel Shiffman.

```auto

// Daniel Shiffman
// Depth thresholding example

// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/

// Original example by Elie Zananiri
// http://www.silentlycrashing.net

import org.openkinect.processing.*;

Kinect2 kinect2;

import codeanticode.syphon.*;
SyphonServer server;

// Depth image
PImage depthImg;

// Which pixels do we care about?
int minDepth = 0;
int maxDepth = 4500; //4.5m

// What is the kinect's angle
float angle;
float frame;

void setup() {
  size(640, 480, P2D);
  server = new SyphonServer(this, "Processing Syphon");

  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();

  frame = 60;

  // Blank image
  depthImg = new PImage(kinect2.depthWidth, kinect2.depthHeight);
}

void draw() {
  // Draw the raw image
  //image(kinect2.getDepthImage(), 0, 0);

  // Threshold the depth image
  int[] rawDepth = kinect2.getRawDepth();

  for (int i=0; i < rawDepth.length; i++) {
    if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
      //float ratio = (maxDepth - minDepth)/255.0;
      depthImg.pixels[i] = color(0);
    } else {
      depthImg.pixels[i] = color(255);
    }
  }

  // Draw the thresholded image
  depthImg.updatePixels();
  image(depthImg, 0, 0, 640, 480);
  
  //fill(0);
  //rect(0, 0, width, frame);
  //rect(0, height-frame, width, frame);
  //rect(0, 0, frame, height);
  //rect(width-frame, 0, frame, height);

  fill(255);
  text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
  server.sendScreen();
}

// Adjust the angle and the depth threshold min and max
// range from 0 to 4500
void keyPressed() {
  if (key == 'a') {
    minDepth = constrain(minDepth+100, 0, maxDepth);
  } else if (key == 's') {
    minDepth = constrain(minDepth-100, 0, maxDepth);
  } else if (key == 'z') {
    maxDepth = constrain(maxDepth+100, minDepth, 1165952918);
  } else if (key =='x') {
    maxDepth = constrain(maxDepth-100, minDepth, 1165952918);
  }
}

```

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [September 6, 2018, 5:02am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/2 "2018-09-06T05:02:35Z")

</div>

Hi,

Have you tried blur + threshold?  
You should be able to reduce the noise like this.

Edit:  
Is was able to get the following result with phtoshop using almost that technique.  
Instead of a pure threshold though, I tweaked a bit the level of the image.

![ImgLvl](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8adde63f6130661fe42c27049503adfee78344ec.jpeg)

For a pure threshold, the 3 sliders would be at the same position. As you can see it’s not far from it 🙂

Here’s the result:

![ImgTestv2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/575c17d6454a19fecbdeee3a8e61f75b412d34e3.jpeg)

Note that you might loose precision with this method, areas can grow or shrink a little.

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 6, 2018, 7:23am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/3 "2018-09-06T07:23:38Z")

</div>

Thanks! The effect is perfect! How can I do this in Processing?

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [September 6, 2018, 7:40am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/4 "2018-09-06T07:40:11Z")

</div>

Check out this function: [https://processing.org/reference/filter\_.html](https://processing.org/reference/filter_.html)  
Both blur and threshold are in it.

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 6, 2018, 9:09am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/5 "2018-09-06T09:09:39Z")

</div>

Thanks. I tried that, but it doesn’t work like photoshop…

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [September 6, 2018, 12:04pm UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/6 "2018-09-06T12:04:17Z")

</div>

You should be able to get a result quite similar than the one with photoshop.  
It might need some tweeking though.

I don’t have processing right now so I can’t try ☹

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [September 6, 2018, 3:43pm UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/7 "2018-09-06T15:43:34Z")

</div>

I manage to get this result with processing and the 2 functions we talked about:

![Result](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/723e1170685835a46b0917d001e0eb5a2bda241b.png)

As you can see it is pretty close to the result from phtoshop.

Here is a code to play with the parameter of the blur and the one of the threshold.

- o : decrease blur value
- p: increase blur value
- l: decrease threshold value
- m: increase threshold value

I’m sorry if the keys make no sense with your keyboard but it makes sense with a french one 🙂

```auto
PImage originalPic;
int paramBlur;
float paramThreshold;

void setup() {
  size(1275, 959);
  
  originalPic = loadImage("test.png");
  paramBlur = 2;
  paramThreshold = 0.3;
}

void draw() {
  image(originalPic, 0, 0);
  filter(BLUR, paramBlur);
  filter(THRESHOLD, paramThreshold);
  
  fill(0);
  noStroke();
  rect(0, 0, 150, 50);
  fill(255);
  text("Blur value: " + paramBlur, 10, 20);
  text("Threshold value: " + paramThreshold, 10, 40);
}

void keyPressed() {
  if (key == 'o') {
    paramBlur--;
    if (paramBlur == -1) {
      paramBlur = 0;
    }
  }
  
  if (key == 'p') {
    paramBlur++;
    if (paramBlur == 10) {
      paramBlur = 10;
    }
  }
  
  if (key == 'l') {
    paramThreshold -= 0.1;
    if (paramThreshold < 0) {
      paramThreshold = 0;
    }
  }
  
  if (key == 'm') {
    paramThreshold += 0.1;
    if (paramThreshold > 1) {
      paramThreshold = 1;
    }
  }
}

```

To try the code, you will need to create a “Data” folder in your sketch folder and put the image below that you will name “test.png”

 ![test](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a5dc2bb0937b9767b5d037afdebf89d0338549bf.jpeg)

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [September 7, 2018, 3:05am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/8 "2018-09-07T03:05:59Z")

</div>

You should look also into erode and dilate: [https://processing.org/reference/PImage\_filter\_.html](https://processing.org/reference/PImage_filter_.html)

Kf

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 7, 2018, 7:48am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/9 "2018-09-07T07:48:28Z")

</div>

Hi, I tried with this… it makes the noise point fewer but bigger…

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 10, 2018, 3:17am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/10 "2018-09-10T03:17:58Z")

</div>

It works great, but only on processing. My idea is to use syphon to transfer the image from processing to resolume arena. When I use the filter, the points are much more fewer than before, but when I transfer the image to arena, it is the same just like before. I also tried openCV: opencv.dilate(); opencv.erode(); opencv.blur(2); , it works but it doesn’t have parameter.

 ![combine1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/de2285700c9566dad5590b10b33c7107351c2180.jpeg)

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 10, 2018, 3:23am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/11 "2018-09-10T03:23:21Z")

</div>

It is the same problem just like my reply. I can’t transfer this image to arena…

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [September 10, 2018, 6:04am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/12 "2018-09-10T06:04:05Z")

</div>

Are you sure your are exporting the right image. It feels that you are exporting the original one?

Can you put here the code that you use to export your image?

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 10, 2018, 7:25am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/13 "2018-09-10T07:25:45Z")

</div>

I think so… I send the image at the very last step…

```auto

// Daniel Shiffman
// Depth thresholding example

// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/

// Original example by Elie Zananiri
// http://www.silentlycrashing.net
import gab.opencv.*;
import org.openkinect.processing.*;
import codeanticode.syphon.*;

SyphonServer server;
Kinect2 kinect2;
OpenCV opencv;

// Depth image
PImage depthImg;

// Which pixels do we care about?
int minDepth = 0;
int maxDepth = 4500; //4.5m

// What is the kinect's angle
float angle;
float frame;

void setup() {
  size(640, 480, P2D);

  server = new SyphonServer(this, "Processing Syphon");

  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();

  frame = 30;

  // Blank image
  depthImg = new PImage(kinect2.depthWidth, kinect2.depthHeight);
      opencv = new OpenCV(this, kinect2.depthWidth, kinect2.depthHeight);

}

void draw() {
  // Draw the raw image
  //image(kinect2.getDepthImage(), 0, 0);

  // Threshold the depth image
  int[] rawDepth = kinect2.getRawDepth();
  

  for (int i=0; i < rawDepth.length; i++) {
    if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
      //float ratio = (maxDepth - minDepth)/255.0;
      depthImg.pixels[i] = color(255);
    } else {
      depthImg.pixels[i] = color(0);
    }
  }

  // Draw the thresholded image
  depthImg.updatePixels();

  try {
    opencv.loadImage(depthImg);
    //opencv.dilate();
    //opencv.erode();
    opencv.blur(2);
    image(opencv.getSnapshot(), 0, 0, 640, 480);

  }
  catch(Exception e) {
    print(e);

  }

  fill(0);
  noStroke();
  //rect(0, 0, width, frame+30);
  //rect(0, height-frame, width, frame);
  //rect(0, 0, frame, height);
  //rect(width-frame, 0, frame, height);

  fill(255);
  text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
  server.sendScreen();
}

// Adjust the angle and the depth threshold min and max
// range from 0 to 4500
void keyPressed() {
  if (key == 'a') {
    minDepth = constrain(minDepth+100, 0, maxDepth);
  } else if (key == 's') {
    minDepth = constrain(minDepth-100, 0, maxDepth);
  } else if (key == 'z') {
    maxDepth = constrain(maxDepth+100, minDepth, 1165952918);
  } else if (key =='x') {
    maxDepth = constrain(maxDepth-100, minDepth, 1165952918);
  }
}

```

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 10, 2018, 7:27am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/14 "2018-09-10T07:27:22Z")

</div>

I think so… I send the image at the very last step…

```auto

// Daniel Shiffman
// Depth thresholding example

// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/

// Original example by Elie Zananiri
// http://www.silentlycrashing.net
import gab.opencv.*;
import org.openkinect.processing.*;
import codeanticode.syphon.*;

SyphonServer server;
Kinect2 kinect2;
OpenCV opencv;

// Depth image
PImage depthImg;

// Which pixels do we care about?
int minDepth = 0;
int maxDepth = 4500; //4.5m

// What is the kinect's angle
float angle;
float frame;

void setup() {
  size(640, 480, P2D);

  server = new SyphonServer(this, "Processing Syphon");

  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();

  frame = 30;

  // Blank image
  depthImg = new PImage(kinect2.depthWidth, kinect2.depthHeight);
      opencv = new OpenCV(this, kinect2.depthWidth, kinect2.depthHeight);

}

void draw() {
  // Draw the raw image
  //image(kinect2.getDepthImage(), 0, 0);

  // Threshold the depth image
  int[] rawDepth = kinect2.getRawDepth();
  

  for (int i=0; i < rawDepth.length; i++) {
    if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
      //float ratio = (maxDepth - minDepth)/255.0;
      depthImg.pixels[i] = color(255);
    } else {
      depthImg.pixels[i] = color(0);
    }
  }

  // Draw the thresholded image
  depthImg.updatePixels();

  try {
    opencv.loadImage(depthImg);
    //opencv.dilate();
    //opencv.erode();
    opencv.blur(2);
    image(opencv.getSnapshot(), 0, 0, 640, 480);

  }
  catch(Exception e) {
    print(e);

  }

  fill(0);
  noStroke();
  //rect(0, 0, width, frame+30);
  //rect(0, height-frame, width, frame);
  //rect(0, 0, frame, height);
  //rect(width-frame, 0, frame, height);

  fill(255);
  text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
  server.sendScreen();
}

// Adjust the angle and the depth threshold min and max
// range from 0 to 4500
void keyPressed() {
  if (key == 'a') {
    minDepth = constrain(minDepth+100, 0, maxDepth);
  } else if (key == 's') {
    minDepth = constrain(minDepth-100, 0, maxDepth);
  } else if (key == 'z') {
    maxDepth = constrain(maxDepth+100, minDepth, 1165952918);
  } else if (key =='x') {
    maxDepth = constrain(maxDepth-100, minDepth, 1165952918);
  }
}

```

---

<div class="post-metadata">

### Author: ![baoter](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/baoter/32/1388_2.png) [@baoter](https://discourse.processing.org/u/baoter)
#### Post date: [September 10, 2018, 7:28am UTC](https://discourse.processing.org/t/question-about-noise-point-reduction/3306/15 "2018-09-10T07:28:28Z")

</div>

I think so, I send the image at the very last step…

```auto

// Daniel Shiffman
// Depth thresholding example

// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/

// Original example by Elie Zananiri
// http://www.silentlycrashing.net
import gab.opencv.*;
import org.openkinect.processing.*;
import codeanticode.syphon.*;

SyphonServer server;
Kinect2 kinect2;
OpenCV opencv;

// Depth image
PImage depthImg;

// Which pixels do we care about?
int minDepth = 0;
int maxDepth = 4500; //4.5m

// What is the kinect's angle
float angle;
float frame;

void setup() {
  size(640, 480, P2D);

  server = new SyphonServer(this, "Processing Syphon");

  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();

  frame = 30;

  // Blank image
  depthImg = new PImage(kinect2.depthWidth, kinect2.depthHeight);
      opencv = new OpenCV(this, kinect2.depthWidth, kinect2.depthHeight);

}

void draw() {
  // Draw the raw image
  //image(kinect2.getDepthImage(), 0, 0);

  // Threshold the depth image
  int[] rawDepth = kinect2.getRawDepth();
  

  for (int i=0; i < rawDepth.length; i++) {
    if (rawDepth[i] >= minDepth && rawDepth[i] <= maxDepth) {
      //float ratio = (maxDepth - minDepth)/255.0;
      depthImg.pixels[i] = color(255);
    } else {
      depthImg.pixels[i] = color(0);
    }
  }

  // Draw the thresholded image
  depthImg.updatePixels();

  try {
    opencv.loadImage(depthImg);
    //opencv.dilate();
    //opencv.erode();
    opencv.blur(2);
    image(opencv.getSnapshot(), 0, 0, 640, 480);

  }
  catch(Exception e) {
    print(e);

  }

  fill(0);
  noStroke();
  //rect(0, 0, width, frame+30);
  //rect(0, height-frame, width, frame);
  //rect(0, 0, frame, height);
  //rect(width-frame, 0, frame, height);

  fill(255);
  text("THRESHOLD: [" + minDepth + ", " + maxDepth + "]", 10, 36);
  server.sendScreen();
}

// Adjust the angle and the depth threshold min and max
// range from 0 to 4500
void keyPressed() {
  if (key == 'a') {
    minDepth = constrain(minDepth+100, 0, maxDepth);
  } else if (key == 's') {
    minDepth = constrain(minDepth-100, 0, maxDepth);
  } else if (key == 'z') {
    maxDepth = constrain(maxDepth+100, minDepth, 1165952918);
  } else if (key =='x') {
    maxDepth = constrain(maxDepth-100, minDepth, 1165952918);
  }
}

```
