• Post Reply Bookmark Topic Watch Topic
  • New Topic

Computing the neighbor pixels of a pixel  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I have this pseudo code:



I'm having trouble figuring out how to compute the neighbors of a certain pixel? I know that there needs to be some kind of 2D array involved.
I have this so far:


I'm getting an index out of bounds exception and not sure why. Any help would be great, thanks.
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's this line that's the problem.

How big of an array do you think you're creating here and how many "dimensions" do you think it has?

I write "dimensions" (in quotes) because arrays in Java are nested (arrays within arrays), not multidimensional. But it's fine if you still want to think of them as multidimensional.
 
Taylor Callihan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to create a 3x3 array, but when i tested the line



And it still gave me the same out of bounds error. I was told that the number of neighbors is dynamic. So like 4 corner pixels will only have 3 neighbors, while the rest will have a different amount.
Not really sure how i should approach this.
 
Taylor Callihan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:It's this line that's the problem.

How big of an array do you think you're creating here and how many "dimensions" do you think it has?

I write "dimensions" (in quotes) because arrays in Java are nested (arrays within arrays), not multidimensional. But it's fine if you still want to think of them as multidimensional.


I replied but forgot to quote, sorry!
My reply above ^
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taylor Callihan wrote:I was told that the number of neighbors is dynamic. So like 4 corner pixels will only have 3 neighbors, while the rest will have a different amount.
Not really sure how i should approach this.


The array provides its length via a length field. And obviously, the smallest index is zero. So, before you check a neighbor, check that it is a valid neighbor with an index between zero (inclusive) and length (exclusive).

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!