Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 05-14-2007, 11:56 AM   #1 (permalink)
Registered User
 
Join Date: May 2007
Posts: 7
OS: XP


C programming Help

i need help writing a program for a "shrinking array". i have no idea where to start and urgently need to know this for a class...

the question is something like this.

if you have a large array say:
0 1 2 4 5 7 5 4 2 1 0
1 2 3 5 6 8 6 5 3 2 1
2 3 4 6 7 9 7 6 4 3 2
4 5 6 8 9 11 9 7 6 5
etc (more numbers)

you want it to be "shrunken" into a array like this:
2 4 6 4 2
4 7 9 7 4
6 9 11 9 6
4 7 9 7 4
2 4 6 4 2

where the numbers in the shrunken array are the averages of a 3x3 from the large matrix. Ie the 2 in the top corner of the shruken array is found by:
(0+1+2+1+2+3+2+3+4)/9. this similar work is done for the numbers found in the shrunken array.

the question asks to write a function that has a symbolic constant SIZE that represents the number of rows and columns in the larger array. and that SIZE will always be odd and greater than or equal to 3. This function must work for any original image of dimensions SIZE by SIZE and must accept the larger source array and the smaller target array as arguements.

it also says not to use any printf(" or scanf(" statements.


thanks for your help guys, any is appreciated... i am desperate in searching for a solution for this.

This is what i have.
Code:
reduce()
int row, col;

for (row = 0; row < rowNum; row++)  
{
   for (col = 0; col < colNum; col++)   
{
       not sure what to put in here
   }
}
believe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 05-20-2007, 11:53 AM   #2 (permalink)
Registered User
 
Join Date: May 2007
Posts: 6
OS: WinXP media center


Re: C programming Help

This problem is named a convolution (in this case, it is a 2D convolution). If you "shrunk" an image using this method, you can blur it.

You must calculate an average over submatrices with size NxN, then you must:
- Calculate sums over submatrices with size NxN
- Divide the result by NxN

If the original matrix is m[][], and the matrix storing the result is r[][], a possible solution is like the following one:

#define N_mid 1
#define N (2*N_mid+1)

for (row = N_mid; row < rowNum-N_mid; row++)
{
for (col = N_mid; col < colNum-N_mid; col++)
{
r[row-N_mid][col-N_mid]=0;
// Make a sum over a sub-matrix with size NxN
for (i = -N_mid; i <= N_mid; i++)
{
for (j = -N_mid; j <= N_mid; j++)
{
r[row-N_mid][col-N_mid]=r[row-N_mid][col-N_mid]+m[row+i][col+j];
}
}
// Divide by N*N
r[row-N_mid][col-N_mid]=r[row-N_mid][col-N_mid]/(N*N);
}
}

The code can seem complicated, but it only makes sums over sub-matrices with size N*N and then divides by N*N.
Lonco is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 09:47 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85