0

I am trying to threshold a PGM in C. I am trying to access the array and trying to convert array elements from one color and then other array elements into another color.

The array is set to the following: int inputPicture[1025][1025];

The code that I am using to access the array and convert the array elements is the following:

int i;
int j;

for (int i = 0; i < MAX_HEIGHT; ++i)
{
    for (int j = 0; j < MAX_WIDTH; ++j)
    {
        if (inputPicture[i][j] >= 1)
        {
            inputPicture[i][j] = 0;
        }
    }
    if (inputPicture[i][j] == 0)
    {
        inputPicture[i][j] = 3;
    }
}

I have set it up as a nested for loop to access the values in the array for the max_height(rows) and the max_width(columns) of the array.

For a PGM file, 0 is the color black, and normally 255 is the color white. However I was instructed that the maximum value for this array should be 3, so I assume that 3 is the color white.

Basically, what I am trying to determine here is if the code above would achieve the desired result of changing the colors in the desired picture, making what was once the color black white, and was white, black.

Or am I doing something wrong? Should a defined function be used instead with pass by pointers?

Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46

0 Answers0