CNN not working

#1

Literally no idea why it doesn’t work plz help

Code
PImage ini;
PImage reo;
String[] log = {};
int[][] con = {
{-1,0,1},
{-1,0,1},
{-1,0,1}
};
int cropsize = 10;

void setup() {
  ini = loadImage("img.png");
  reo = ini;
  
  for ( int x = cropsize ; x < ini.width-cropsize ; x++ ) {
    for ( int y = cropsize ; y < ini.height-cropsize ; y++ ) {
      
      int r = 0;
      int g = 0;
      int b = 0;
      
      color c1 = ini.get(x-1,y-1);
      color c2 = ini.get(x-1,y);
      color c3 = ini.get(x-1,y+1);
      color c4 = ini.get(x,y-1);
      color c5 = ini.get(x,y);
      color c6 = ini.get(x,y+1);
      color c7 = ini.get(x+1,y-1);
      color c8 = ini.get(x+1,y);
      color c9 = ini.get(x+1,y+1);
      
      r+=int(red(c1*con[0][0]));
      r+=int(red(c2*con[1][0]));
      r+=int(red(c3*con[2][0]));
      r+=int(red(c4*con[0][1]));
      r+=int(red(c5*con[1][1]));
      r+=int(red(c6*con[2][1]));
      r+=int(red(c7*con[0][2]));
      r+=int(red(c8*con[1][2]));
      r+=int(red(c9*con[2][2]));
      
      g+=int(green(c1*con[0][0]));
      g+=int(green(c2*con[1][0]));
      g+=int(green(c3*con[2][0]));
      g+=int(green(c4*con[0][1]));
      g+=int(green(c5*con[1][1]));
      g+=int(green(c6*con[2][1]));
      g+=int(green(c7*con[0][2]));
      g+=int(green(c8*con[1][2]));
      g+=int(green(c9*con[2][2]));
      
      b+=int(blue(c1*con[0][0]));
      b+=int(blue(c2*con[1][0]));
      b+=int(blue(c3*con[2][0]));
      b+=int(blue(c4*con[0][1]));
      b+=int(blue(c5*con[1][1]));
      b+=int(blue(c6*con[2][1]));
      b+=int(blue(c7*con[0][2]));
      b+=int(blue(c8*con[1][2]));
      b+=int(blue(c9*con[2][2]));
      
      if (r>255) r=255;
      if (g>255) g=255;
      if (b>255) b=255;
      
      if (r<0) r=0;
      if (g<0) g=0;
      if (b<0) b=0;
      
      reo.set(x,y,color(r,g,b));
      
      log = append(log, "X:" + x + " Y:" + y + " R:" + r + " G:" + g + " B:" + b + "| R:" + int(red(c5)) + " G:" + int(green(c5)) + " B:" + int(blue(c5)));
    }
  }
  saveStrings("log.txt", log);
  reo.save("out.png");
  print("DONE");
}
0 Likes

#2

What happens and what do you want to happen instead?

Which lines are relevant for this?

0 Likes

#3

You probably want to create a new PImage for reo and not link back to the same memory.
That’s just a wild shot at a problem I see might occur. I don’t know what you are trying to achieve either, so please answer to Chrisirs post if you still need help.

0 Likes