Print Array of image in terminal

Hello everyone. I’m interested in printing the array data of an image in terminal. For example in python I load the image, then I only use print(image) to see the array list of the picture. In processing this is not as trivial as I thought.

Here is my code

def setup():
    size(500,500)
    global img
    img = loadImage("Image.png")
    loadPixels()
    printArray(img)
    
def draw():
    background(255)
    image(img,0,0)

Thanks in advance.

Py.Processing.org/reference/pixels.html

1 Like

In Processing (Java):

PImage myImage;

void setup() 
  {
  size(100, 100);
  myImage = loadImage("apples.png");
  myImage.loadPixels();
  printArray(myImage.pixels);
  }

void draw() 
  {
  image(myImage, 0, 0);
  }

Started here and modified:

I see category changed to Python now…

:)

Ok, now I write the example but the value is not an RGB color.

def setup():
    size(11,11)
    global img
    img = loadImage("prueba.png")
    image(img,0,0)
    loadPixels()
    print(pixels)
    
def draw():
    background(255)
    image(img,0,0)

It is worth pointing that the size of the image is (10x5)px and it returns the following

Then I realized in the description of pixels feature that I need to write

color b = pixels[index]

But it returns me an error of compilation

def setup():
    size(11,11)
    global img
    img = loadImage("prueba.png")
    image(img,0,0)
    loadPixels()
    color b = pixels[1]
    print(b)
    
def draw():
    background(255)
    image(img,0,0)

Maybe there’s an unclosed paren or quote mark somewere before this line?

We don’t declare a variable’s datatype on Python 2! So it’s just: b = pixels[1]

3 Likes