I am given a matrix of elements of dimensions **Width**x**Height** which is allocated dynamically. I need to "crop" a part of this matrix defined by the rectangle formed by: (start\_col, start\_line) (end\_col, end\_line)

---

**Example:**

Given the matrix (3\*3):

```
1 2 3
4 5 6
7 8 9

```

And the coords: (1, 1) (1, 1)

The resulting matrix is:

```
5

```

How would I do this? 

---

My matrix consists of struct elements like this:

```
typedef struct Pixel{
   int R;
   int G;
   int B;
}Pixel;

```

And so I declared and allocated the matrix like this:

```
Pixel** img;

img = (Pixel**)malloc(height*sizeof(Pixel*));
for (int i = 0; i <= height-1; i++){
    img[i] = (Pixel*)malloc(width*sizeof(Pixel));
}

// ...
//code to populate matrix

```

Now how should I use realloc to keep just the small submatrix that I need?