Unsure why convolution matrix index is incorrect

So I'm suppose to make a convolution matrix. An 8x8 and a 3x3 to make a 6x6. What I'm planning to do was find the sum of the 3x3 and multiply the sum of the 8x8 starting from the top left [0-2][9-11][17-19] store the result on a 6x6 matrix at [0][0] then move one column to the right of the 8x8, so and it'll then multiply it by [1-3][10-12][18-20] and store the result in the 6x6 at [0][1] and repeat until it reaches the end then it'll start back on the 0 column but shift the row of the 8x8 by 1.

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
int eightArray[8][8];
  int a[6][6];
  int something = 0;
	int threeRow = 0, threeColumn = 0, counterOne = 0, counterTwo = 0, column = 0, row = 0;
 for(int i = threeRow; i < 8; i++){
		for(int j = threeColumn; j < 8; j++){
			counterOne++;
			something += eightArray[i][j];
			cout << i << " " << j << "  ";
			// After it checks 3 three column it goes to the next row
			if(counterOne % 3  == 0){
				cout << endl;
				break;
			}
		}
		// After it checks three rows the sum of 3x3 matrix within the 8x8 is found
		++counterTwo;
		if(counterTwo % 3  == 0){
			i = threeRow;
			cout << endl;
			// Set the 6x6 matrix with the product
			a[row][column] = something;
			something = 0;
			// Starts reading the 8x8 matrix on the next column
			threeColumn++;
			column++;
			// Can only shift it 6 times before out of range
			if(column % 6 == 0){
				cout << endl << "Next set" << endl;
				// Resets the column back to 0
				threeColumn = 0;
				column = 0;
				// Starts reading from next row
				threeRow++;
				row++;
				// After reading 6 rows, breaks out of loop
				if(row % 6 == 0){
					break;
				}
			}
		}
	}


If you run the code the first set of outputs are:
0 0  0 1  0 2  
1 0  1 1  1 2  
2 0  2 1  2 2  

Suppose to be 0,1,2 for the first column of each set:

1 1  1 2  1 3  should be : 0 1 0 2 0 3
2 1  2 2  2 3  should be : 1 1 1 2 1 3
3 1  3 2  3 3  should be : 2 1 2 2 2 3

1 2  1 3  1 4  
2 2  2 3  2 4  
3 2  3 3  3 4  

1 3  1 4  1 5  
2 3  2 4  2 5  
3 3  3 4  3 5  

1 4  1 5  1 6  
2 4  2 5  2 6  
3 4  3 5  3 6  

1 5  1 6  1 7  
2 5  2 6  2 7  
3 5  3 6  3 7 

Last edited on
Hello arbwok,

When I found your post it was green checked which tells most people that you re done with the post and have an answer. A good reason you have not received any response.

I did not know if this bit of code is to be put in main or a function. I put it in main and it worked for now.

When I started working on your program I found that each array needed to be initialized, so I did. After initializing the "a" array I wrote a set of nested for loops to set the "a" array to 1's. Later I noticed the program changed the "a" array back to 0's.

I also noticed that the "eightArray" never receives any values and the "something" variable is always 0, not very useful.

After running the program many times I changed line 9 to std::cout << i << " " << j << " X"; so I could see what was happening and realized the only output is coming from line 9 and not from any array. Hard to get your desired output when the only output is coming from your for loop iterators.

There needs to be some changes, but I have not figured out where yet. Your instructions are good, but some parts I do not completely understand yet.

Hope that helps,

Andy
Topic archived. No new replies allowed.