Change Saturation of an Image

Hi,
I’m trying to figure out how to change the saturation of an image, I can change its brightness, hue, invert it, but just can’t wrap my head around changing saturation (in the hope that i can put it on a slider, and have it with a load of other effects, to create a basic image processor)
Could someone give me a nudge in the right direction?

My current idea is this:

img.loadPixels();
  imgCopy.loadPixels();
  

  for (int i = 0; i <= img.width * img.height - 1; i=i+1) {
      s = 20;
    r = red(img.pixels[i]); 
    g = green(img.pixels[i]);
    b = blue(img.pixels[i]);
    
   
    if (r > g && r > b){
    r += s;
    g -= s;
    b -= s;
    }
   if (g > b && g > r){
    r -= s;
    g += s;
    b -= s;
    }
  if (b > r && b > g){
    r -= s;
    g -= s;
    b += s;
    }
    

    
    imgCopy.pixels[i] = color(r, g, b);
    
  }
  
  img.updatePixels();
  imgCopy.updatePixels();
}

Thanks for the help.

Thanks for the question! Please format forum code with three ``` above and below, or highlight your code and use the </> button in the editor toolbar. Get rid of those little < and > before and after.

Your color data will always be stored internally as ARGB. However, if you want to display saturation, you can use saturation(c) on any color.

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

If you want to create or change colors in terms of saturation, use colorMode(HSB).

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

3 Likes

Hi Jeremy,

Thank you for the reply, sorry I missed understood and thought the little < > before and after was the right thing.

Thanks that’s really helpful