jpegtran.exe无法正确旋转图像 [英] jpegtran.exe not correctly rotating image

查看:187
本文介绍了jpegtran.exe无法正确旋转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新编译的libjpeg版本9,并尝试在命令行中使用以下参数运行jpegtran.exe:

I have a freshly compiled libjpeg version 9 and tried running jpegtran.exe in command line with the arguments:

.\jpegtran.exe -rotate 180 -outfile test_output1.jpg testimg.jpg

testimg.jpg: test_output1.jpg:

testimg.jpg: test_output1.jpg:

如您所见,它确实会旋转图像,但会对其进行裁剪,并且无法正确组合在一起.软件包附带的usage.txt文件不是最新的,因为我不得不使用-outfile开关来代替它:

As you can see it does rotate the image but it clips it and it's not put together correctly. The usage.txt file that comes with the package isn't totally up to date because I had to use the -outfile switch instead of what it says:

jpegtran使用类似于cjpeg或djpeg的命令行语法.在 类似于Unix的系统,您会说:

jpegtran uses a command line syntax similar to cjpeg or djpeg. On Unix-like systems, you say:

  • jpegtran [开关] [输入文件]>输出文件

在大多数非Unix系统上,您说:

On most non-Unix systems, you say:

  • jpegtran [切换]输入文件输出文件

其中输入和输出文件均为JPEG 文件.

where both the input and output files are JPEG files.

要指定在输出文件中使用的编码的JPEG表示形式, jpegtran接受cjpeg识别的一部分开关:

To specify the coded JPEG representation used in the output file, jpegtran accepts a subset of the switches recognized by cjpeg:

  • -optimize进行熵编码参数的优化.
  • -progressive创建渐进式JPEG文件.
  • -arithmetic使用算术编码.
  • -restart N每N个MCU行或每N个MCU块(如果在数字后加上"B")发出JPEG重新启动标记.
  • -扫描文件使用指定文本文件中提供的扫描脚本.
  • -optimize Perform optimization of entropy encoding parameters.
  • -progressive Create progressive JPEG file.
  • -arithmetic Use arithmetic coding.
  • -restart N Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is attached to the number.
  • -scans file Use the scan script given in the specified text file.

有关这些的更多详细信息,请参见前面对cjpeg的讨论 开关.如果您不指定任何这些开关,则会得到一个普通的 基线JPEG输出文件.质量设置等是 由输入文件确定.

See the previous discussion of cjpeg for more details about these switches. If you specify none of these switches, you get a plain baseline-JPEG output file. The quality setting and so forth are determined by the input file.

通过提供以下任意一项,可以无损地变换图像 开关:

The image can be losslessly transformed by giving one of these switches:

  • -水平翻转水平镜像(左右).
  • -垂直翻转垂直镜像(上下).
  • -旋转90度将图像顺时针旋转90度.
  • 旋转180度将图像旋转180度.
  • -旋转270顺时针旋转图像270度(或90 ccw).
  • -转置转置图像(跨UL-to-LR轴).
  • -横向横向转置(跨UR-to-LL轴).
  • -flip horizontal Mirror image horizontally (left-right).
  • -flip vertical Mirror image vertically (top-bottom).
  • -rotate 90 Rotate image 90 degrees clockwise.
  • -rotate 180 Rotate image 180 degrees.
  • -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw).
  • -transpose Transpose image (across UL-to-LR axis).
  • -transverse Transverse transpose (across UR-to-LL axis).

奇怪的是(或者也许不是),如果我执行.\jpegtran.exe -rotate 180 -outfile test_output2.jpg test_output1.jpg,我可以得到原始图像而没有任何裁剪问题.它正在翻转剪切的部分,但只是没有使其与图像的其余部分对齐.

Oddly enough (or maybe not), if I execute .\jpegtran.exe -rotate 180 -outfile test_output2.jpg test_output1.jpg I get the original image back without any clipping issues. It's flipping the clipped parts but just not lining it up right with the rest of the image.

test_output2.jpg:

test_output2.jpg:

我执行两次jpegtran.exe -rotate 90可获得相同的结果.

I get the same result by executing jpegtran.exe -rotate 90 twice.

此外,我在一个较大的.jpg文件上尝试了此操作,这导致了相同的问题,但输出文件的大小减小了18KB.我想这个问题与此有关.

Also, I tried it on a larger .jpg file which resulted in the same issue but the file size was 18KB smaller for the output. I imagine the issue is related to this.

编辑-我也发现了这个blurb,似乎可以说明问题所在:

Edit - I also found this blurb which seems to describe the problem:

jpegtran转换奇数尺寸图像时的默认行为是 旨在保持精确的可逆性和数学一致性 转换集.如前所述,转置能够翻转 整个图像区域.水平镜像可保留所有部分iMCU 右边缘的列保持不变,但能够翻转 图片.同样,垂直镜像会保留任何部分iMCU行 底部边缘未触及,但能够翻转所有列.这 其他转换可以建立为转置和翻转序列 操作;为了保持一致,定义了它们对边缘像素的操作 与相应的最终结果相同 转置和翻转序列.

jpegtran's default behavior when transforming an odd-size image is designed to preserve exact reversibility and mathematical consistency of the transformation set. As stated, transpose is able to flip the entire image area. Horizontal mirroring leaves any partial iMCU column at the right edge untouched, but is able to flip all rows of the image. Similarly, vertical mirroring leaves any partial iMCU row at the bottom edge untouched, but is able to flip all columns. The other transforms can be built up as sequences of transpose and flip operations; for consistency, their actions on edge pixels are defined to be the same as the end result of the corresponding transpose-and-flip sequence.

-trim开关可以工作,如果可以调用它的话,它可以修剪掉混乱的数据,但是图像较小并且丢失了数据.

The -trim switch works, if you can call it that, and trims out the disorganized data but the image is smaller and lost data.

test_output5.jpg:

test_output5.jpg:

添加-perfect开关可以阻止上述情况的发生,结果是:transformation is not perfect用于输出并且没有图像.

Adding the -perfect switch which supposedly stops the above from happening results in this: transformation is not perfect for output and no image.

那么不可能无损地旋转.jpg吗?我自己可以通过简单地将边缘线移到正确的位置来绘画并重建原始图像.在libjpeg中是否可以执行此操作?

So is it not possible to losslessly rotate a .jpg? I could, myself, go into paint and reconstruct the original image by simply moving the edge lines into their correct place. Is there a method to do this within libjpeg?

推荐答案

无损旋转适用于JPEG文件中包含的整个DCT块.这些块始终为8x8或16x16像素(取决于压缩降采样设置).该文件包含宽度和高度,因此在解码图像时可以丢弃多余的像素,但是无法将剪辑从右/下边缘移动到左/上边缘.该软件正在尽最大努力解决一个不可能的问题.

A lossless rotation works with whole DCT blocks contained within the JPEG file. These blocks are always 8x8 or 16x16 pixels (depending on the compression downsampling settings). The file contains a width and height so the extra pixels can be thrown away when the image is decoded, but there's no way to move the clipping from the right/bottom edge to the left/top edge. The software is doing the best it can with an impossible problem.

您已经发现解决此问题的方法是使宽度和高度可以被16整除.例如,您会发现来自摄像机的图像将具有此属性.

As you've discovered the way around this problem is to make the width and height evenly divisible by 16. You'll find that images from cameras for example will have this property.

这篇关于jpegtran.exe无法正确旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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