# CNN not working

**URL:** <https://discourse.processing.org/t/cnn-not-working/10190>\
**Category:** Coding Questions\
**Created:** [April 11, 2019, 3:51pm UTC](https://discourse.processing.org/t/cnn-not-working/10190 "2019-04-11T15:51:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Odermonicon](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Odermonicon](https://discourse.processing.org/u/Odermonicon)\
**Post date:** [April 11, 2019, 3:51pm UTC](https://discourse.processing.org/t/cnn-not-working/10190/1 "2019-04-11T15:51:09Z")

</div>

Literally no idea why it doesn’t work plz help

> **Code**
>
> ```auto
> 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");
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 11, 2019, 5:45pm UTC](https://discourse.processing.org/t/cnn-not-working/10190/2 "2019-04-11T17:45:08Z")

</div>

What happens and what do you want to happen instead?

Which lines are relevant for this?

---

<div class="post-metadata">

**Author:** ![happymoep](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@happymoep](https://discourse.processing.org/u/happymoep)\
**Post date:** [April 11, 2019, 7:07pm UTC](https://discourse.processing.org/t/cnn-not-working/10190/3 "2019-04-11T19:07:30Z")

</div>

> [@Odermonicon](#):
>
> ini = loadImage(“img.png”);  
> reo = ini;

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 [Chrisir](https://discourse.processing.org/u/Chrisir)s post if you still need help.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 29, 2019, 9:23am UTC](https://discourse.processing.org/t/cnn-not-working/10190/4 "2019-08-29T09:23:50Z")

</div>

Getting the color of a single pixel with **get(x, y)** is easy, but not as fast as grabbing the data directly from **pixels[]**. The equivalent statement to **get(x, y)** using **pixels[]** is **pixels[y\*width+x]**. See the reference for [pixels[]](https://processing.org/reference/pixels.html) for more information.
