2016-10-07 28 views
0

ppmファイルを読み込んで保存しようとしていますが、モジュールの読み込みと保存の正確さを確認しています。しかし、私は貯蓄に関する別の結果を得ることになります。 ピクセル値をMATLABでチェックしたので、ロードモジュールがうまく動作していることを確認しました。 保存モジュールは以下の通りです:PPMファイル、C++で読み書きする

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)をリンクしています。任意の提案、入力は参考になります。ありがとう!

+0

http://stackoverflow.com/a/39808791/2836621 –

答えて

0

私が考えた理由は、型キャスティングと空白です。

ofstream ofs; 
ofs.open("output.ppm", ofstream::out); 
ofs<<"P6\n"<<img_wd<<" "<<img_ht<<"\n"<<max_val<<"\n"; 

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

ofs.close(); 
関連する問題