Insert 2D subarray into bigger 2D array?

I am currently trying to build an IRST for my fathers 60th birthday.
Originally I wanted to use a single point infrared thermometer to scan a 60° x 30° field of view.
However, even if every single point only takes 0.1 seconds, a complete scan will still take 3 minutes.
So I looked into low performance thermal cameras instead and found a relatively cheap breakout board housing an 8x8 infrared sensor.
Now, the new plan is to make the field of view 56° x 32° and essentially insert 28 blocks of what the camera sees.
I have seen that memcpy() was suggested in a post that is similar to what I am looking for, but since I will have one 8x8 block and not just a single line like in that other post, I wanted to ask if it is possible to do it using memcpy, or if I have to do it by using a two stage for-loop.

like this you mean?

#include<stdio.h>
#include <string.h>

int matrixA[2][8] = { 
		             {101, 102, 103,104,105,106,107,108},
		             {201, 202, 203,204,205,206,207,208}
                   };

int matrixB[8][8] = {
                    {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},
                    {0,0,0,0,0,0,0,0},
                    {0,0,0,0,0,0,0,0}
                  };

int main() {
    //assumption
    //matrixB contain initial data (here 6x8 matrix) but has to be created with final matrix size in mind (hence why it is actually and 8x8 matrix)
    //unused rows in final matrix initialised to zeros
    
    for(int i=0; i<8;++i){
        for(int j=0; j<8;++j){
            printf("%i, ",matrixB[i][j]);
        }
        printf("\n");
    }
    
    memmove(&matrixB[5][0],&matrixB[3][0],3*8*sizeof(int)); //3*8 ie rows*columns* size of datatype.block copy data from insertion point (matrixA to be inserted at row 3)
                                                            //and move to end of matrix ie row 3 - 5 now moved to row 5-7
    memcpy(&matrixB[3][0],&matrixA[0][0],2*8*sizeof(int)); //2*8 ie rows*columns* size of datatype. insert in matrix A
    
    printf("\n");
    
    for(int i=0; i<8;++i){
        for(int j=0; j<8;++j){
            printf("%i, ",matrixB[i][j]);
        }
        printf("\n");
    }
    
}

output

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,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,

1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
101, 102, 103, 104, 105, 106, 107, 108,
201, 202, 203, 204, 205, 206, 207, 208,
25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,

hope that helps....

Thanks for your answer!
I would have two arrays:
The sensor array of the camera, which will give me 64 values in an 8x8 formation (Not 100% about the datatype yet, it said it can display half degrees, so I assume they will be floats).
Then there is the search array, which is 56 x 32 degrees.
I basically wanted to copy an 8x8 block into the 56x32 array.
Although now that I think about that, it makes absolutely no sense, because the field of view of the camera is not 8x8 degrees, so it will not be a match.

Besides some finicky motion of the camera?

It does seem like you have identified an entirely additional challenge, make the field of view be, in fact, close to 8 by 8 degrees.

memcpy can do a row at a time, you'll still have to loop over the 8 rows. If you want to form the big matrix.

a7

1 Like

There is another way - you can scan a big matrix by 8x8 blocks, so you memcpy data of the block at once.

Pleas elaborate. I will learn something.

The OP boiled it to

I basically wanted to copy an 8x8 block into the 56x32 array.

The 8x8 is the camera image, the larger array is 28 tiles 7 x 4.

a7

Indeed.
So all what you need - enumerate elements in big array not in row and columns, but by 8x8 tiles, so it will be constructed with blocks, like this:
Снимок35
After that you will be able to do memcpy of the whole 8x8 block at once.

OIC. I didn't realize you had moved the goal posts.

a7

sorry, I dont understand what you mean. My English is not fluent so far.

"Moving the goalposts" is a metaphor. You can google that and read stuff better than I could write.

Used here it means you offered a solution to a problem different to the one the OP is trying to solve.

An interesting idea, perhaps, but not one that the OP can apply in her circumstances.

HTH

a7

1 Like

Why not?
Large array does not have to be a rectangular matrix with continuous rows. The ordering pattern could be different:
pattern
(this picture has nothing to do with OP's array, it just a demonstration of the different scan pattern)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.