从TIFF文件中提取JPEG [英] Extract JPEG from TIFF file

查看:614
本文介绍了从TIFF文件中提取JPEG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景 我有一个大的TIFF文件,该文件是COM pressed与JPEG(在TIFF标准新,玉米pression 7)和平铺。我需要做的就是提取这些瓦片个人.jpg文件。我需要能够做到这一点与出DECOM pressing / RECOM pressing的图像数据,因为这将需要太多的计算资源,这样我才知道是出了问题的所有库。

Background I have a large TIFF file that is compressed with JPEG (new, compression 7 in TIFF standard) and is tiled. What I need to do is extract these tiles to individual .jpg files. I need to be able to do this with out decompressing/recompressing the image data because that will require too much compute resources, so all libraries that I know of are out of the question.

我知道了很多关于TIFF文件的结构,但几乎一无所知JPEG文件结构。我有code写的,现在读的TIFF头到字节数组的JPEGTable标签数据(这意味着它去抵消指向的标签和读取它存在)和code另一个Blurb的读取目标平铺到一个字节数组。然后我写了的字节数组到一个新的文件,然后写的瓷砖的字节数组后,这一文件。最后2字节的的数组我写了为0xFF,0xFF的和相同的前2个字节的瓷砖的数组,因为我发现两个数组开始和结束与JPEG SOI分别EOI序列,如果我有超过1各,该文件不会打开的任何图像程序。

I know a lot about TIFF file structure, but almost nothing about JPEG file structure. I have code written right now that reads the JPEGTable tag data from the tiff header into a byte array (meaning it goes to the offset pointed at by the tag and reads it there) And another blurb of code that reads the target Tile into a byte array. Then I am writing the Table byte array to a new file, then writing the Tile byte array to that file after that. The last 2 bytes of the Table array I write over with 0xFF, 0xFF and the same for the first 2 bytes of the Tile array, because I found that both arrays start and end with the jpeg SOI and EOI sequences respectively and if I had more than 1 of each, the files wouldn't be openable by any image programs.

For i as Integer = 0 to TableArray.Count-3
    stream.WriteByte(TableArray(i))
Next
stream.WriteByte(255)
stream.WriteByte(255)
stream.WriteByte(255)
stream.WriteByte(255)
For i as Integer = 2 to TileArray.Count-1
    stream.WriteByte(TileArray(i))
Next
stream.Close()

问题 所以这就是我现在的问题是,我提取的瓷砖都是阴影粉红色的,它应该是白色的,几乎像一个彩色负片。这并不是固体粉红色的,我可以看到我知道是在原始图像中物体的轮廓。任何人不会有任何想法如何,我也许可以解决此问题?另外,我做这在VB.NET,但我不认为语言真正的问题在这种情况下,因为它似乎更多的是概念/算法/文件结构的问题,我做错了。

Problem So that is where I am right now, the problem is that my extracted tiles are all shaded pink where it should be white, almost like a color negative. It isn't solid Pink, I can see outlines of objects I know are in the original image. Does any one have any ideas how I might be able to solve this? Also, I am doing this in VB.NET, but I don't think the language really matters in this case as it seems to be more of a concept/algorithm/file structure issue I am doing wrong.

如果有人想我张贴一些code,我使用,我可以,只需要知道哪一部分。

If some one would like me to post some of the code I am using, I can, just need to know which part.

编辑:我在Adobe公司的Photoshop TIFF技术说明发现从2002年3月22日一节,上面写着:

I found in the Adobe Photoshop TIFF Technical Notes from March 22, 2002 a section that says:

从TIFF转换为JPEG互换是比较复杂的。带状基于TIFF / JPEG文件可以相当容易地转换,如果所有带使用相同的JPEG表和无RSTn有效标记:刚才删除的开销标记,并插入带之间RSTn有效标志。转换平铺图像是困难的,因为该数据通常不按照正确的顺序(除非砖只需要一个MCU的高点)。这还是可以无损地完成,但它的将需要撤销和重做熵编码使直流系数的差异可以被更新。

Conversion from TIFF to interchange JPEG is more complex. A strip-based TIFF/JPEG file can be converted fairly easily if all strips use identical JPEG tables and no RSTn markers: just delete the overhead markers and insert RSTn markers between strips. Converting tiled images is harder, since the data will usually not be in the right order (unless the tiles are only one MCU high). This can still be done losslessly, but it will require undoing and redoing the entropy coding so that the DC coefficient differences can be updated.

不知道这是有关我的问题或没有。

Not sure if that is relevant to my problem or not.

推荐答案

与Photoshop中制作的TIFF文件的困难在于,它们还可以支持写RGB颜色空间转换成JPEG COM pressed数据。如果您从您的TIFF文件中提取单个区块,并将其写入为独立JPEG图像,将无法正常显示,因为德codeRS假设色彩是的YCbCr。有一个解决方案,只要观看应用尊重的Adobe APP14标记。包括在此标记是一个字节,它定义了变换(色彩空间)。如果您在SOI之前插入这个字节序列,你的形象会在很多观众正确显示。

The difficulty with TIFF files produced by Photoshop is that they support writing the RGB colorspace into JPEG compressed data. If you extract a single tile from your TIFF file and write it as an independent JPEG image, it will not display correctly because decoders assume that the colorspace is YCbCr. There is a solution as long as the viewing application respects the Adobe APP14 marker. Included in this marker is a byte which defines the transform (colorspace). If you insert this sequence of bytes before the SOI, your image will display correctly on many viewers.

FF EE 00 0E 41 64 6F 62 65 00 64 80 00 00 00 00

FF EE 00 0E 41 64 6F 62 65 00 64 80 00 00 00 00

最后一个字节定义的变换;在这种情况下,0表示RGB色彩。你可以阅读更多关于它的:

The last byte defines the transform; in this case 0 indicates the RGB colorspace. You can read more about it here:

甲骨文JPEG元数据文档

这篇关于从TIFF文件中提取JPEG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆