# How to get the color value of an image, not that of what's drawn on the background

**URL:** <https://discourse.processing.org/t/how-to-get-the-color-value-of-an-image-not-that-of-whats-drawn-on-the-background/25642>\
**Category:** Coding Questions\
**Created:** [November 23, 2020, 7:42pm UTC](https://discourse.processing.org/t/how-to-get-the-color-value-of-an-image-not-that-of-whats-drawn-on-the-background/25642 "2020-11-23T19:42:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![papaboo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/papaboo/32/11236_2.png) [@papaboo](https://discourse.processing.org/u/papaboo)\
**Post date:** [November 23, 2020, 7:42pm UTC](https://discourse.processing.org/t/how-to-get-the-color-value-of-an-image-not-that-of-whats-drawn-on-the-background/25642/1 "2020-11-23T19:42:48Z")

</div>

In this example, (no image, I’ve just used a background colour to demonstrate) the background colour value is 25 but when there’s a brush that overlays the background, mouseX and mouseY returns the value of what’s drawn the surface, not the image (background).

How to get the colour value of an image itself even when there’s something drawn onto it?

```auto
    void setup() {
      size(800, 600);
      frameRate(60);
    }
  
    
    void draw() {
           background(25);
      noStroke();
      fill(255, mouseX);
      ellipse(mouseX, mouseY, 30, 30);
      
      color c = get(mouseX, mouseY);
      float shade;
      shade = int(blue(c));
    
    print(shade);
    }

```

By the way, I’m using the blue© to get the grey scale value because the image I’m going to use is black and white, is there any other way to get the b&w value without using r, g or b?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 23, 2020, 7:53pm UTC](https://discourse.processing.org/t/how-to-get-the-color-value-of-an-image-not-that-of-whats-drawn-on-the-background/25642/2 "2020-11-23T19:53:16Z")

</div>

> [@papaboo](#):
>
> How to get the colour value of an image itself even when there’s something drawn onto it?

In theory when imgBackground is your image say `color colFromBackgroundImage = imgBackground.get(mouseX,mouseY)` to get the color of that pixel

> [@papaboo](#):
>
> way to get the b&w value without using r, g or b?

I think there is brightness() command

OR you receive red green blue values, add them (and divide by 3?)? Never tried that.

There is also hue and saturation, dunno, maybe to do with HSB?

> **[Reference](https://www.processing.org/reference/)**
>
> Find further documentation of the Processing language

Warm regards,

Chrisir
