How to adjust Threshold Filter?

edited May 2015 in How To...

I would like to know if there is a way to adjust the threshold filter that comes with Processing?

You can adjust other filters with a value. Such as blur. i.e. filter(BLUR, 4) Why can't this be done with threshold such as filter(THRESHOLD, 125)?

A threshold filter uses a certain color value and then only shows the pixels brighter than that. Without writing my own from the pixels array and use an "if then" statement, I was hoping to do it this way.

Any suggestions?

// Adjusting Threshold filter()

PImage img;

void setup()  {
  // 16 x 9
  size(320, 180);
  img = loadImage("Test Pattern 1.1.jpg");
}

void draw()  {
  background(0);
  image(img, 0, 0, width, height);

  // How can you customize what value the threshold is held against?
  filter(THRESHOLD, 0);
}
Tagged:

Answers

  • edited May 2015 Answer ✓

    From https://processing.org/reference/filter_.html

    THRESHOLD
    Converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. The parameter must be between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.

    Clearly, this accepts a level parameter. Don't be fooled by the example, it just shows the "no level specified" usage of default value.

  • Way too cool. That is the way to do it. I did not think to use the float from 0 to 1. Thanks for the tip. Can this be assumed that it is a pretty low level operation? As in being pretty fast for video processing?

    // Adjusting Threshold filter()
    
    PImage img;
    
    void setup()  {
      // 16 x 9
      size(320, 180);
      img = loadImage("Test Pattern 1.1.jpg");
    }
    
    void draw()  {
      background(0);
      image(img, 0, 0, width, height);
    
      // Use 0.0 to 1.0 to adjust the threshold
      filter(THRESHOLD, 0.33);
    }
    
Sign In or Register to comment.