# Reversing the threshold filter

**URL:** https://discourse.processing.org/t/reversing-the-threshold-filter/13579
**Category:** Coding Questions
**Created:** [August 25, 2019, 3:28am UTC](https://discourse.processing.org/t/reversing-the-threshold-filter/13579 "2019-08-25T03:28:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![eric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eric/32/5988_2.png) [@eric](https://discourse.processing.org/u/eric)
#### Post date: [August 25, 2019, 3:28am UTC](https://discourse.processing.org/t/reversing-the-threshold-filter/13579/1 "2019-08-25T03:28:36Z")

</div>

I’ll throw in only the important parts, but for an image processing application I’m making, I want to analyze the image with the rgb components (typical picture), and then change it to black and white using the threshold filter, and run a few things with black and white. It all happens when I click the mouse, but I can’t seem to get the color photo back. Ideally it would happen in mouseReleased, and I’d run the majority of the code in mousePressed. Let me know with any thoughts, thanks.

```auto
PImage crossSection;

void setup() {
  size(1008, 756);
  crossSection = loadImage("crossSection.jpg");
}

void draw() {
  backgound(0);
  image(crossSection, 0, 0);
  crossSection.resize(1008, 756);
  loadPixels();
  crossSection.loadPixels();
  updatePixels();
}

void mousePressed() {
  //code that needs an RGB photo
  crossSection.filter(THRESHOLD, .85);
  updatePixels();
  //code that needs the black and white version
}

void mouseReleased() {
  //not sure what to put here in order to change the image back to RGB
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [August 25, 2019, 3:41am UTC](https://discourse.processing.org/t/reversing-the-threshold-filter/13579/2 "2019-08-25T03:41:46Z")

</div>

untested,  
but i think that the idea is to run the

```auto
filter();

```

[https://processing.org/reference/filter\_.html](https://processing.org/reference/filter_.html) function  
after the

```auto
image();

```

a temporary loading from mousePressed() might be overwritten by next draw.  
so better use the mouse to change the threshold value only ( used in draw later )

OR  
move the `image();` up into the `setup();` could work too.

* * *

start from:  
/File/Examples/ Basics/Image/LoadDisplayImage/

for operation can try my MouseWheelPlusPlus

```auto
/**
 * Load and Display 
 */

PImage img;
float fset = 0.50;
boolean fenable = false;

void setup() {
  size(640, 360);
  img = loadImage("moonwalk.jpg"); // Load the image into the program
  println("click on canvas, press \n click toggle enable filter\n key [f] and turn mousewheel");
}

void draw() {
  image(img, 0, 0);
  if ( fenable ) filter(THRESHOLD,fset);
}
void mouseWheel(MouseEvent event) {
  float e = event.getCount(); //println(e);
  if ( keyPressed && key == 'f' ) { 
    fset += e/10.0 ;
    println(" key f: fset "+fset);
  }
}

void mousePressed() {
  fenable = ! fenable; 
}

```

---

<div class="post-metadata">

### Author: ![eric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eric/32/5988_2.png) [@eric](https://discourse.processing.org/u/eric)
#### Post date: [August 25, 2019, 4:53am UTC](https://discourse.processing.org/t/reversing-the-threshold-filter/13579/3 "2019-08-25T04:53:12Z")

</div>

It worked, thank you very much!
