How to know if certain pixel is red, or blue, or green

I want to change colors from of a certain image, so all the reds will be certain blue,
and all the blues will be certain blue.

in order to do that, I am looking for some logic in the colors numbers, so I can use a simple if.

for example, all red have H150 or more, and G100 or less and B100 or less.

Any idea ?


Take a look here:

There is a search on the upper right… search for related keywords.


you could use red(), green(), blue(), pixels array

I already extract the R, G and B of the pixel.

Now, I want to check if it is some kind of red (from few thousands shades of red).

This is what I’m looking for


Search for color on the Processing website.

There is also hue, saturation and brightness that you can work with.


if you got the RED, GREEN and BLUE values, and the requirement to turn red would be R>150, G>100, B>100. So just put that into an if statement. Repeat for all oolors.


Processing has a Color Selector… that is in the Tools menu:



1 Like

The main idea is to analyze an image, so I can change it’s color to a dozen color,
so, I’m looking for an easy way to the check the red, green and blue of a color, and determine which color is it,
of example - I want to mark as a red all the variation from the top right corner of the image you’ve paste.

So, I basically looking for a formula, because it happen to be more than 100k different shades in a 1200X1200 pixel image

well a simple solution would be to search the distance on a 3D color cube. If a color must be either Red, green or blue, you can just find the closest point. Posterization filters work in a similar way (can work).

here is a project that incorporates it.

Below is some p5.js code that might accomplish what you are trying to do. Note what the color_checker function does. Pass it a color along with ranges for the red, green, blue, and alpha components, and it will return true if all components fall within their designated ranges, and false otherwise.

The code below draws a bluish square, then checks the colors of all the pixels. The bluish pixels are turned to red. It can easily be translated to Java.

// p5.js code
function setup() {
  createCanvas(200, 200);
  frameRate(1); // enable observer to see color change

function draw() {
  background(255, 255, 0);
  fill(0, 0, 216); // note that blue component is 216
  rect(width / 4, height / 4, width / 2, height / 2);
  if (frameCount == 2) {
    for (let x = 0; x <= width; x++) {
      for (y = 0; y <= height; y++) {
        c = get(x, y);
        // note range for blue
        if (color_checker(c, 0, 255, 0, 255, 210, 220, 0, 255)) {
          fill(255, 0, 0);
          square(x, y, 1);

function color_checker(c, r_lo, r_hi, g_lo, g_hi, b_lo, b_hi, a_lo, a_hi) {
  given a color object, and low and high values (inclusive), for r, g, b, and a,
   true if all color components are within the specifed ranges,
   otherwise false
  let r = red(c);
  let g = green(c);
  let b = blue(c);
  let a = alpha(c);
  return (
    (r >= r_lo) && (r <= r_hi) &&
    (g >= g_lo) && (g <= g_hi) &&
    (b >= b_lo) && (b <= b_hi) &&
    (a >= a_lo) && (a <= a_hi)