Solved

finding sum of nxn matirx data

Posted on 2003-11-03
7
248 Views
Last Modified: 2010-04-17
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
Comment
Question by:rickynair
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
JNSTAUB earned 35 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 100

Expert Comment

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

mlmcc
0
 
LVL 2

Expert Comment

by:wellilein
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 100

Expert Comment

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

mlmcc
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 70
nestparen challenge 4 56
mapShare challenge 13 68
base64 decode encode 12 96
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now