Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# finding sum of nxn matirx data

Posted on 2003-11-03
Medium Priority
295 Views
Hi,

i have an array of pixel data. x,y value of each pixel is known.
I have to find the sum of nxn pixels around the given pixel(including the pixel)

that is for the pixel at (x,y). 3x3 sum will be
(x-1,y+1)+(x,y+1)+(x+1,y+1)+(x+1,y)+(x,y)+(x+1,y-1)+(x,y-1)+(x-1,y-1)+(x-1,y).

This calculation should be dynamic, that is for any nxn , the sum should be computed.
i would like to know the way to go abt doing this.

regards,
ric
0
Question by:rickynair
• 2

LVL 4

Accepted Solution

JNSTAUB earned 140 total points
ID: 9669808
you have to create a function:

function filter_pixel(x,y,n)
if x>1 AND y>1 and x<n-1 and y<n-1 then
filter_pixel=(x-1,y+1)+(x,y+1)+(x+1,y+1)+(x+1,y)+(x,y)+(x+1,y-1)+(x,y-1)+(x-1,y-1)+(x-1,y)
else
all the border' case
else

end if
end function
0

LVL 101

Expert Comment

ID: 9671786
Why are you trying to do this?  Is this homework perhaps?

mlmcc
0

LVL 2

Expert Comment

ID: 9672411
Try it with a nested loop

funct filterpixel(x,y,n)
int sum=0
for int i=x-n to x+n
for int k=y-n to y+n
sum += getPixelValueAtPosition(i,k)
return sum
end funct

and implement a function named getPixelValueAtPosition() that checks if pixel coordinates are inside your image and returns the pixel value for it.

Above code is not valid for any programming language, so if it is homework, it's not a complete solution. Is that ok this way, mlmcc?
0

LVL 101

Expert Comment

ID: 9673004
You will need to subtract the value at (x,y)

mlmcc
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress
###### Suggested Courses
Course of the Month14 days, 10 hours left to enroll