How to extract pictrure 0-255 value in a matrix

edited December 2016 in How To...

Hi, I want to extract the luminosity value of the pixels of greyscale images as a matrix in a .txt file, process them mathematicaly in a suitable program (e.g excel) and recombine them in a new image. I'm totaly ignorant about programming so any help would be of great help. Thanks



  • Answer ✓

    look here:

    When you got this:

    This code is supposed to read a file:

    PImage tower;
    void setup() {
      size(600, 200);
      tower = loadImage("P6LFNRLPISUT.png");
      int dimension = tower.width * tower.height;
      String[] ca1  = new String [dimension]; 
      for (int i = 0; i < dimension; i++) {
        color c1 = tower.pixels[i];
        ca1[i] = str( brightness(c1)) ; 
        //ca1[i] = red(c1)+","
        //  +green(c1)+","
        //  +blue(c1);
      // tower.updatePixels();
      saveStrings("text1.csv", ca1);
    void draw() {
      image(tower, 0, 0);
  • See also get() in the reference.


    process them mathematicaly in a suitable program (e.g excel)

    This is (probably) a really bad idea. It is much, much easier (and faster, and more reliable) to mathematically process matrices of pixels using the Processing language, rather than exporting them to Excel, doing math on them, then reimporting them.

  • Answer ✓

    If you provide details of your calculations on your brightness and how it will be recombined with your original image, it could be implemented here on chrisir's code. Just give it a try!


  • Anything that can be done in excel can be done in Processing. So why use excel?

  • Thank you a lot for your help!!!

    The math that I want to do is very simple; like summing or averaging the (Xi,Yj) pixel of two images or to maintain the relative values of the pixels' luminosity of an image while setting their sum to a specific value. I'm sure that using excel is a very large detour, and I think that if a get a proper result on some tests that I' m running, I' ll try to use code in processing.

  • Good decision. Excel (or such other software) will only complicate the process more.

Sign In or Register to comment.