テスト用に .j2k ファイルに含まれている JPEG 2000 ファイルストリームから高品質レイヤーを抽出しようとしています。ファイルストリームを送信する方法を学び、最終的に関心領域 (ROI) の選択を実行するために、これを実行しようとしています。これらのことをデコードせずに実行したいのですが、今のところ唯一のユーティリティは OpenJPEG ライブラリです。
image_to_j2k ユーティリティ (Linux) を使用して、テスト イメージを .j2k ファイルに含まれるファイル ストリームに変換しました。次に、.j2k ファイルをバイナリ モードでバッファーに読み込みました。
long fsize = get_file_size("img.j2k"); //This does what it's supposed to
char* buffer = new char[fsize];
ifstream in ("img.j2k", ios::in | ios::binary);
in.read(buffer, fsize); //The entire file goes into the buffer
ofstream out1("out1.j2k");
ofstream out2("out2.j2k");
ofstream out3("out3.j2k");
//This is where I try to truncate the filestream
out1.write(buffer, fsize); //Write the entire file to out1.j2k - this works
out2.write(buffer, 11032); //Write 11032 bytes of the filestream to out2.j2k - this does not to what I thought it would
out3.write(buffer, 14714); //Write 14714 bytes of the filestream to out2.j2k - this does not to what I thought it would
in.close();
out1.flush();out1.close();
out2.flush();out2.close();
out3.flush();out3.close();
out2 および out3 ファイルに書き込まれるバイト数は、ランダムに選択されるのではなく、OpenJPEG が圧縮中に作成するインデックス ファイルから取得されます。ファイルを最初から取得し、品質レイヤーの最後に対応する「end_pos」マーカーがあることをインデックス ファイルが示す特定のポイントまで読み取ると、ファイル - これが最終的な目標です。ファイルをワイヤレスでフォレスト内に送信し、フォレスト内の別の場所にあるハンドヘルド デバイスまたはラップトップで画像を段階的により良い品質で表示することです。out2.j2k および out3.j2k ファイルで j2k_to_image を使用しようとした結果は次のとおりです。
[ERROR] JPWL: bad tile byte size (1307053 bytes against 10911 bytes left)
[ERROR] 00000081; expected a marker instead of 1
ERROR -> j2k_to_image: failed to decode image!
私はこれを完全に間違った方法で行っていますか? JPEG 2000 を使用しないことは論外です。回答に感謝します。このことに関するドキュメントを実際に調べましたが、この詳細が見つかりません。