Grayscaling a given image

image

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
And while I’m on the topic, how to get the color of a pixel?

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

Hi @CodeMasterX

The following code should grey scale your image

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 :slight_smile: I believe they will be useful to you

How to get pixels of image

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

How to get color of pixel of Image

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

Tutorial on Pixels and Images

https://processing.org/tutorials/pixels/

Best regards

2 Likes