# Grayscaling a given image

**URL:** <https://discourse.processing.org/t/grayscaling-a-given-image/26768>\
**Category:** Beginners\
**Created:** [January 4, 2021, 11:07am UTC](https://discourse.processing.org/t/grayscaling-a-given-image/26768 "2021-01-04T11:07:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 4, 2021, 11:07am UTC](https://discourse.processing.org/t/grayscaling-a-given-image/26768/1 "2021-01-04T11:07:27Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/24d60cad02a849e2b94f2e380159af6526699740.png)

```auto
PImage org = loadImage("data/99484011-ead8-482a-a169-820c7981896f.jpg"), gray = org;
void settings() {
  size(org.width*2,org.height);
  gray.filter(GRAY);
}
void draw() {
  image(org,0,0);
  filter(GRAY);
  image(gray,org.width+1,0);
}

```

what did I do wrong?

The data/ folder contains this image  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2e0f3ba507c8f665d03159d9f201c6a559cefa97.png)  
And while I’m on the topic, how to get the color of a pixel?

```auto
void mousePressed() {
   color pick = pixels[floor(mouseX)+width*floor(mouseY)]
}

```

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [January 4, 2021, 11:28am UTC](https://discourse.processing.org/t/grayscaling-a-given-image/26768/2 "2021-01-04T11:28:57Z")

</div>

Hi @CodeMasterX

The following code should grey scale your image

```auto
PImage img;
 
void setup(){
  size(300,300);
  img = loadImage("data/99484011-ead8-482a-a169-820c7981896f.jpg.jpg");
  image(img, 0, 0);
  filter(GRAY);
  filter(THRESHOLD,0);
  loadPixels();
}

```

Also, have a look at the following links 🙂 I believe they will be useful to you

> **How to get pixels of image**
>
> [https://processing.org/reference/PImage\_pixels.html](https://processing.org/reference/PImage_pixels.html)

> **How to get color of pixel of Image**
>
> [https://processing.org/reference/get\_.html](https://processing.org/reference/get_.html)

> **Tutorial on Pixels and Images**
>
> [https://processing.org/tutorials/pixels/](https://processing.org/tutorials/pixels/)

Best regards
