the problem consists in mirror an image pnm horizontally. in my code, the image is treated as a array 3d, which every coordinated keeps save an value of rgb.
so, i tried to solve this by putting all of these values on another array. So, I created a loop, declared a variable equal to the width initially, and applied a degrowth to it, as well as a growth to the other, which started at 0. Thus, when assigning the array to the other, the first column would shift to the last, mirroring the image gradually. However, the treatment of the image was not as expected, and I can’t find where the error is. I generated some prints of the matrices before, during the loop and after. The problem is really in this first loop, since the values do not come out mirrored as expected. The image reading, processing and recording is done previously in the code, this part is correct as it works normally in other functions.
important point : imagem[][][] is Initialized as an 3d array where is record all those values previously.
When I compile and run the program and open a 4×2 image, as there are 3 RGB colors, it has 24 values. Printing as int the imagecolor array before transcribing the mirror image to vcor, and after, something unexpected occurs(aint mirroring, but some values are changed in a way dont understand). The transcription back from VCOR to imagecolor is correct.
I’ll let the result of the print of (int)imagemcor before the first loop, another print of the result of vcor after the first loop and another result of the print of (int)imagemcor after the same.
vimagem[2][4][3]= 100 100 100 100 100 100 100 100 100 100 100 0 0 255 0 0 0 255 0 0 0 (before)
vcor[2][4][3]=0 0 255 0 255 153 255 0 0 0 0 0 100 100 100 100 100 100 100 100 100 0 100 100
here we notice that this aint mirroring.
vimagem[2][4][3]=0 0 255 0 255 153 255 0 0 0 0 0 100 100 100 100 100 100 100 100 100 0 100 100(after)
at least the copy part its ok.
the code is :
unsigned char vcor[altura][largura][3];
for( int p=largura-1, j=0; j<largura; j++, p--){
for(int i=0; i<altura;i++){
for(int k=0; k<3; k++){
vcor[i][p][k]=imagemcor[i][j][k];
}
}
}
for (int i=0; i<altura; i++){
for(int j=0; j<largura; j++){
for(int k=0; k<3; k++){
imagemcor[i][j][k]= vcor[i][j][k];
}
}
}
palazzo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.