# Finding the edges in an Image error

**URL:** <https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055>\
**Category:** Coding Questions\
**Created:** [January 14, 2021, 10:36am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055 "2021-01-14T10:36:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)\
**Post date:** [January 14, 2021, 10:36am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/1 "2021-01-14T10:36:11Z")

</div>

I’ve written this code to find the edges in my image which I have named properly in the correct file:

\<PImage frog;

void setup(){  
size(1200,720);  
frog=loadImage(“frog.jpg”);  
}

void draw(){  
loadPixels();  
frog.loadPixels();  
for(int x=0; x\<width-4; x++){  
for(int y=0; y\<height; y++){  
int loc1=x+y\*width;  
int loc2=(x+1)\*width;  
float b1=brightness(frog.pixels[loc1]);  
float b2=brightness(frog.pixels[loc2]);  
float diff=abs(b1-b2);  
pixels[loc1]=color(diff);  
}  
}  
updatePixels();  
}

> 

And I keep getting this error:  
‘‘ArrayIndexOutOfBoundsException: 864000  
Could not run the sketch (Target VM failed to initialize).  
For more information, read revisions.txt and Help ? Troubleshooting.’’

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 14, 2021, 11:01am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/2 "2021-01-14T11:01:31Z")

</div>

You’re locations at some points are not found within the pixel array. Add some bools to check if locations are greater than 0 and less than pixel array length.

---

<div class="post-metadata">

**Author:** ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)\
**Post date:** [January 14, 2021, 11:07am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/3 "2021-01-14T11:07:40Z")

</div>

What do you mean books? sorry i’m new here

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 14, 2021, 11:08am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/4 "2021-01-14T11:08:29Z")

</div>

Soz autocorrect. Meant bools.

---

<div class="post-metadata">

**Author:** ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)\
**Post date:** [January 14, 2021, 11:09am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/5 "2021-01-14T11:09:19Z")

</div>

you mean in the form of if diff\<20 for example?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 14, 2021, 11:10am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/6 "2021-01-14T11:10:08Z")

</div>

Yes. You just need to check you’re locations are within the pixel array

---

<div class="post-metadata">

**Author:** ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)\
**Post date:** [January 14, 2021, 11:34am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/7 "2021-01-14T11:34:33Z")

</div>

I don’t understand exactly how I can write this. If the sketch doesn’t run in the first place how is it supposed to run after I write it?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 14, 2021, 11:42am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/8 "2021-01-14T11:42:55Z")

</div>

You need to place

```auto
float b1=brightness(frog.pixels[loc1]);
float b2=brightness(frog.pixels[loc2]);
float diff=abs(b1-b2);
pixels[loc1]=color(diff);

```

Within appropriate statements

---

<div class="post-metadata">

**Author:** ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)\
**Post date:** [January 14, 2021, 11:44am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/9 "2021-01-14T11:44:08Z")

</div>

how would that look like?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 14, 2021, 11:46am UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/10 "2021-01-14T11:46:09Z")

</div>

```auto
if(condition1) {

} 

if(condition2) {

} 

```

Or

```auto
if(condition1 && condition2) {

} 

```

This should be fairly simple as I’ve already detailed what the conditions are.

---

<div class="post-metadata">

**Author:** ![ELaN](https://avatars.discourse-cdn.com/v4/letter/e/3e96dc/32.png) [@ELaN](https://discourse.processing.org/u/ELaN)\
**Post date:** [January 14, 2021, 2:10pm UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/11 "2021-01-14T14:10:11Z")

</div>

Turns out I had forgotten to write (x+1)+y\*width. It was the +y I had forgotten about damn my eyes are worthless

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 14, 2021, 2:18pm UTC](https://discourse.processing.org/t/finding-the-edges-in-an-image-error/27055/12 "2021-01-14T14:18:49Z")

</div>

If we could only get back the hours spent debugging eh.
