gpt4 book ai didi

c++ - jpegtran.exe 无法正确旋转图像

转载 作者:太空宇宙 更新时间:2023-11-04 11:59:48 25 4
gpt4 key购买 nike

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

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

testimg.jpg:before test_output1.jpg:after

如您所见,它确实旋转了图像,但它对其进行了裁剪并且没有正确组合在一起。软件包附带的 usage.txt 文件并不完全是最新的,因为我不得不使用 -outfile 开关而不是它所说的:

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

  • jpegtran [switches] [inputfile] >outputfile

On most non-Unix systems, you say:

  • jpegtran [switches] inputfile outputfile

where both the input and output files are JPEG files.

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

  • -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.

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:

  • -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 我会得到原始图像,没有任何裁剪问题。它会翻转剪裁的部分,但不会将其与图像的其余部分对齐。

test_output2.jpg:after another rotate 180

我通过执行两次 jpegtran.exe -rotate 90 得到相同的结果。

此外,我在一个更大的 .jpg 文件上进行了尝试,这导致了同样的问题,但输出的文件大小小了 18KB。我想这个问题与此有关。


编辑 - 我还发现了这个似乎描述问题的简介:

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 开关有效,如果你可以这样调用它的话,它会修剪掉杂乱无章的数据,但图像变小并且丢失数据。

test_output5.jpg:trimmed output

添加 -perfect 开关,据说可以阻止上述情况的发生,结果是:transformation is not perfect for output and no image.

所以不能无损旋转 .jpg 吗?我自己可以通过简单地将边缘线移动到正确的位置来进行绘画和重建原始图像。有没有在 libjpeg 中执行此操作的方法?

最佳答案

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

正如您所发现的那样,解决此问题的方法是使宽度和高度能被 16 整除。您会发现例如来自相机的图像将具有此属性。

关于c++ - jpegtran.exe 无法正确旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14612809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com