我正在尝试从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是不可能的。感谢任何答案,我真的已经完成了关于这件事的文档,但是找不到这个细节。