简体   繁体   English

在C或C ++中翻转灰度图像?

[英]GrayScale Image Flip in c or c++?

I am trying to flip a gray scale image horizontally. 我正在尝试水平翻转灰度图像。 Pointer fp is pointing to original image and pointer fp1 is creating horizontally flipped image. 指针fp指向原始图像,而指针fp1创建水平翻转的图像。 The Program is executing properly but the output image is worst... 程序执行正常,但输出图像最差...

    for( i =0 ;i<width ; i++)
     for(j=0; j <height; j++)
              idata[i][height - 1 -j] = ( (unsigned char)fgetc(fp));
    //flipping image          
for( i =0 ;i<width ; i++)
     for(j=0; j <height; j++)
              putc(idata[i][j] , fp1);                

there is no problem in header copy of image. 图像的标题副本没有问题。 i think problem is residing in for loop... plz help me out 我认为问题存在于循环中...请帮助我

Are you sure you are not mixing up width and height? 您确定您没有混合使用宽度和高度吗? The code seems to assume that the data is read in a column wise order when it most likely is in a row wise order. 该代码似乎假定最有可能按行顺序读取数据时按列顺序读取。 Try flipping the for loops and the dimension for flipping, like so: 尝试翻转for循环和翻转尺寸,如下所示:

for(j = 0; j < height; j++)
    for(i = 0; i < width; i++)
        idata[width - 1 - i][j] = ( (unsigned char)fgetc(fp));

//flipping image          

for(j = 0; j < height; j++)
    for(i = 0; i < width; i++)
        putc(idata[i][j] , fp1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM