2

I have a programming issue regarding the extraction of a subimage (submatrix) from a bigger image (matrix). I have two points (upper and lower bound of the subimage i want to extract) and i want to extract the subimage from the bigger one based on these points. But I can't find how to do thins with C/C++.

I know it's very easy to do with matlab. Suppose these two points are (x_max,y_max) and (x_min,y_min). To extract the subimage I just need to code the following:

(MATLAB CODE)-> small_image=big_image(x_min:x_max,y_min,y_max); 

But in C i can't use an interval of indexes with : as i do with Matlab. Does anybody here faced this problem before?

Amro
  • 123,847
  • 25
  • 243
  • 454
mad
  • 2,677
  • 8
  • 35
  • 78

2 Answers2

2

If you are doing image processing in C/C++, you should probably use OpenCV.

The cv::Mat class can do this using a Region Of Interest (ROI).

Simon
  • 31,675
  • 9
  • 80
  • 92
1

In straight c++, you'd use a loop.

int* small_im[]; // or whatever the syntax is

int i = 0, j = 0;
for (i = 0; i < (x_max-x_min); i++)
{
    for (j = 0; j < (y_max-y_min); j++)
    {
      small_im[i][j] = big_im[x_min+i][y_min+j];
    }
}
Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Frederick
  • 1,271
  • 1
  • 10
  • 29