cropping pgm file with 2d vector
Sep 24, 2016 at 5:29am UTC
I attempted to write a function that crops a pgm file which is stored in a 2d vector that is passed to the function. The rectangle starts at row r and column c and has number of rows is in rows. the number of columns is in columns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
void pgm_crop( vector <IVec> p, int r, int c, int rows, int cols )
{
int count = 0; //first count variable
int count2 = 0; // 2nd count variable
for ( count = 0; count < r; count++ )
{
if ( count + 1 != r )
{ p.erase( p.begin() + count ); // erase rows before given point
}
else
p.resize( rows ); // resize to number of rows for( count2 = 0; count2 < c; count2++ )
{
if ( count2 + 1 != c )
{ p[count].erase( p[count].begin() + count2 ); // erase elements before given point
}
else p[count].resize( cols ); // resize to number of columns
}
}}
My output is not right. any ideas on how to fix it?
Topic archived. No new replies allowed.