turn any grey pixels to full white

edited March 2018 in How To...

hi, I am creating an image with fine strokes, resulting in some pixels that are various shades of grey. What I want to do is go through each pixel and if it is not fully black, make it fully white. I've been using set(xx, yy, color(255)); to successfully set pixels, but when I use the "get" command, the numbers it returns aren't sensible?

How can I determine when a pixel colour is not black please??

(p.s. I know I should be using Pixels() etc but am not that advanced yet!)

thanks in advance!

Answers

  • Also, the reference for color:

    From a technical standpoint, colors are 32 bits of information ordered as AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB where the A's contain the alpha value, the R's are the red value, G's are green, and B's are blue. Each component is 8 bits (a number between 0 and 255).

  • i am not fully sure how to solve it

    did you solve it?

    maybe this:

    https://processing.org/reference/brightness_.html

  • edited March 2018 Answer ✓

    Just use an if statement and re-write the color.

      for (int x = 0; x<bw.pixels.length; x++) {
            if (bw.pixels[x] >= color(25)) {
             bw.pixels[x] =  color(255);
            }
          }
    

    Example:

    PImage bw;
    
    void setup() {
    
      size(100, 100);
      bw = createImage(width, height, RGB);
    }
    
    void draw() {
      background(0);
    
      loadPixels();
      for (int x = 0; x<width; x++) {
        for (int y =0; y<height; y++) {
          int index = x + (y*width);
          float distance = 10*width/dist(width/2, height/2, x, y);
          pixels[index] = color(distance);
        }
      }
      updatePixels();
    
      bw = get();
      bw.loadPixels();
      for (int x = 0; x<bw.pixels.length; x++) {
        if (bw.pixels[x] >= color(25)) {
         bw.pixels[x] =  color(255);
        }
      }
    
      bw.updatePixels();
      image(bw,0,0);
    }
    
  • thanks! - yes this works - seems to work when using the "Pixels" construct. I now understand that color is a 32bit RGBA value :)

Sign In or Register to comment.