PPM文件,用C ++读写

时间:2016-10-07 01:11:12

标签: c++ matlab ppm

我正在读取ppm文件,然后尝试保存它,以查找我的加载和保存模块的准确性。但我最终得到了不同的储蓄结果。 我用MATLAB检查了像素值,所以我非常确定我的加载模块运行良好。 保存模块如下:

ofstream ofs;
ofs.open("output.ppm", ofstream::out);
ofs<<"P6"<<endl;
ofs<<"# File after convolution"<<endl;
ofs<<img_wd<<" "<<img_ht<<endl; //check if ASCII conversion is needed
ofs<<max_val<<endl;

for(int j=0; j <img_ht;j++)
{
    for (int i=0; i<img_wd;i++)
    {
        ofs<<static_cast<char>(Pixel[j][i].r)<<static_cast<char>(Pixel[j][i].g)<<static_cast<char>(Pixel[j][i].b);  //write as ascii
    }
    ofs<<endl;
}

我正在链接实际文件(https://github.com/aditisingh/Image_convolution_2D/blob/master/start_1.ppm)和已保存文件(https://github.com/aditisingh/Image_convolution_2D/blob/master/output.ppm)。任何建议,输入都会有所帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

我认为的原因是,类型转换和空格。

$autoload['libraries'] = array('database');