Hi, I am currently doing a program that reads an image in the targa format, does some processing on it and then write back in a new image. If I just read and write it without any changes, it work fine.
If I try to do any kind of processing, I end with a bizarre image with the elements of the image appertaining several times. At first I thought that the problem was in the algorithm I was applying, a mean filter that was causing it.
But then I decided to simplify the image to try to see what is happening. So I had the idea of "erase" it, making it all white, with a single black square in part of the image to see if it would show up as expected. That's the simplest thing I could think. This is the code that does this square drawing:
I tested with a 2-dimension vector and the result was the same.
I think the reason may be related with targa format, which is why I am thinking about trying another file format. Outside that I have no idea about how I can figure out what's happening and would appreciate any suggestions about how I can try to find out what's going on.
int index( int width, int x, int y )
{
return 3 * (y * width + x);
}
So:
1 2 3 4 5 6 7 8 9 10 11 12
// Fill image with white
fill_n( image, 3 * width * height, 255 );
// Draw a pretty green (RGB = #73C36C) square at (left, top, right, bottom)
for (int x = left; x <= right; x++)
for (int y = top; y <= bottom;
{
int n = index( width, x, y );
image[ n + 0 ] = 115;
image[ n + 1 ] = 195;
image[ n + 2 ] = 108;
}
Ok, it worked. Thanks a lot. But my doubt remains....... Why wasn't my code working?
I was working with the image's pixels in a row-column order. Your code deals with them in a column-row order. Both should work, but only the second one indeed works. Why? ANyone has an idea?