Problem looping through a 4D array

Thank you for your kind words, was a pleasure to work with you. :wink:

Warm regards,

Chrisir

P.S.

When you look at setup() again

void setup() {
  size(1900, 800);
  background(0) ; 
  noSmooth();
  noStroke();
  frameRate(13);

  img = loadImage("process1.png"); // "fashion_MNist_01.png");
  img.resize (200, 200);

  // fill image grid
  myList = new PixelRepresentation[img.width][img.height];

  // fill permuts 
  for (int i=0; i<256; i++) {
    permuts[i] = new  ListOfPermuts( i );
  }//for
  fillpermuts () ;

  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++ ) {
      // Calculate the 1D pixel location
      int loc = x + y*img.width;
      color c1=img.pixels[loc]; 
      myList[x][y] = new PixelRepresentation (c1, x*5, y*5);
    }// for
  }// for
}// setup

from an aesthetically point of view:

the parts concerning

  • image, img and PixelRepresentation (it’s for image) should be one section,
  • and only after that the section with permuts;
    so better version:
void setup() {
  size(1900, 800);
  background(0) ; 
  noSmooth();
  noStroke();
  frameRate(13);

  // load image 
  img = loadImage("process1.png"); // "fashion_MNist_01.png");
  img.resize (200, 200);

  // prepare and fill image grid "myList"
  myList = new PixelRepresentation[img.width][img.height];
  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++ ) {
      // Calculate the 1D pixel location
      int loc = x + y*img.width;
      // get color 
      color c1 = img.pixels[loc]; 
      // store color and future position 
      myList[x][y] = new PixelRepresentation (c1, x*5, y*5);
    }// for
  }// for

  // prepare and fill permuts 
  for (int i=0; i<256; i++) {
    permuts[i] = new  ListOfPermuts( i );
  }//for
  fillpermuts () ;

}// setup

Remark

Also I made the function int count(int no) which is a variation of Richard’s is3bits().

It counts how many 1’s there are in a bit pattern thus determine also its brightness (from 0 to 12).

I use this an index for permuts[] array.

When retrieving data from permuts I map (use map() command) the brightness from 0…255 to 1…12 to use this as an index for permuts[].

Remark

Since binary() gives you the bit pattern as a String (length 12) I use this (with charAt()) to fill the 3x4 fields representing the patterns for each pixel.

1 Like