我正在尝试从 JPEG 2000 文件流中提取质量层,该文件流包含在 .j2k 文件中以进行测试。我试图这样做是为了学习如何传输文件流,并最终对其执行感兴趣区域 (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 是不可能的。感谢您提供任何答案,我确实浏览了有关此内容的文档,但找不到此详细信息。