![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| 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: * 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 |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#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
}
}
|
|
|
|
| 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 |
|
|
#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. |
|
|
|
![]() |
| Thread Tools | |
|
|