项目作者: ImageProcessing-ElectronicPublications

项目描述 :
Utilities for lossy recompress JPEGs
高级语言: C
项目地址: git://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress.git
创建时间: 2018-07-05T03:31:04Z
项目社区:https://github.com/ImageProcessing-ElectronicPublications/jpeg-recompress

开源协议:MIT License

下载


GitHub release (latest by date)
GitHub Release Date
GitHub repo size
GitHub all releases
GitHub

JPEG Recompress

Utilities for archiving photos for saving to long term storage or serving over the web. The goals are:

  • Use a common, well supported format (JPEG)
  • Minimize storage space and cost
  • Identify duplicates / similar photos

Approach:

  • Command line utilities and scripts
  • Simple options and useful help
  • Good quality output via sane defaults

Contributions to this project are very welcome.

Download

You can download the latest source and binary releases from the JPEG Recompress releases page.

Utilities

The following utilities are part of this project. All of them accept a --help parameter to see the available options.

jpeg-recompress

Compress JPEGs by re-encoding to the smallest JPEG quality while keeping perceived visual quality the same and by making sure huffman tables are optimized. This is a lossy operation, but the images are visually identical and it usually saves 30-70% of the size for JPEGs coming from a digital camera, particularly DSLRs. By default all EXIF/IPTC/XMP and color profile metadata is copied over, but this can be disabled to save more space if desired.

There is no need for the input file to be a JPEG. In fact, you can use jpeg-recompress as a replacement for cjpeg by using PPM input and the --ppm option.

The better the quality of the input image is, the better the output will be.

Some basic photo-related editing options are available, such as removing fisheye lens distortion.

Demo

Below are two 100% crops of Nikon’s D3x Sample Image 2. The left shows the original image from the camera, while the others show the output of jpeg-recompress with the medium quality setting and various comparison methods. By default SSIM is used, which lowers the file size by 88%. The recompression algorithm chooses a JPEG quality of 80. By comparison the veryhigh quality setting chooses a JPEG quality of 93 and saves 70% of the file size.

JPEG recompression comparison

Why are they different sizes? The default quality settings are set to average out to similar visual quality over large data sets. They may differ on individual photos (like above) because each metric considers different parts of the image to be more or less important for compression.

Image Comparison Metrics

The following metrics are available when using jpeg-recompress. SUM is the default.

Name Option Description
MPE -m mpe Mean pixel error (as used by imgmin)
PSNR -m psnr Peak signal-to-noise ratio
MSE -m mse Mean squared error
MSEF -m msef sqrt(MSE/Variance)
Correlation -m cor Correlation
SSIM -m ssim Structural similarity
MS-SSIM* -m ms-ssim Multi-scale structural similarity (slow!) (2008 paper)
VIFP1 -m vifp1 The visual information fidelity (VIF) 1 layer.
SmallFry -m smallfry Linear-weighted BBCQ-like (original project, 2011 BBCQ paper -> LibSmallFry)
SharpenBad -m shbad Sharpen discrepancies (LibSmallFry)
NHW -m nhw NHW convolutional metric (original project -> LibSmallFry)
1 pair -m ssimfry (ssim + smallfry) / 2
2 pair -m ssimshb (ssim + shbad) / 2
SUMMARY -m sum (ssim + vipf1 + smallfry + shbad + nhw) / 5 DEFAULT

Note: The SmallFry algorithm may be patented so use with caution.

“Universal Scale” of metrics (UM):

UM example

  1. 0.0
  2. ... (DIRTY) ...
  3. 0.5
  4. ... (LOW) ...
  5. 0.75
  6. ... (MEDIUM) ...
  7. 0.875
  8. ... (SUBHIGH) ...
  9. 0.9375
  10. ... (HIGH) ...
  11. 0.96875
  12. ... (VERYHIGH) ...
  13. 1.0

Trends:

  1. UM = 0.29 * (sqrt(sqrt(255.0 / MPE)) - 1.0)
  2. UM = 0.557 * (sqrt(PNSR) - 5.0)
  3. UM = 0.5 * (sqrt(sqrt(1.0 / MSEF)) - 1.0)
  4. UM = 1.0 * cor_sigma(cor_sigma(COR))
  5. UM = 1.57 * cor_sigma(cor_sigma(cor_sigma(SSIM)))
  6. UM = 1.59 * cor_sigma(cor_sigma(MS_SSIM))
  7. UM = 1.10 * cor_sigma(cor_sigma(VIFP1))
  8. UM = 3.0 * (SMALLFRY * 0.01 - 0.8)
  9. UM = 1.46 * cor_sigma(SHARPENBAD)
  10. UM = 0.342 * (sqrt(sqrt(1.0 / NHW)) - 1.0)
  11. cor_sigma(M) = 1.0 - sqrt(1.0 - M * M)

Subsampling

The JPEG format allows for subsampling of the color channels to save space. For each 2x2 block of pixels per color channel (four pixels total) it can store four pixels (all of them), two pixels or a single pixel. By default, the JPEG encoder subsamples the non-luma channels to two pixels (often referred to as 4:2:0 subsampling). Most digital cameras do the same because of limitations in the human eye. This may lead to unintended behavior for specific use cases (see #12 for an example), so you can use --subsample disable to disable this subsampling.

Example Commands

  1. # Default settings
  2. jpeg-recompress image.jpg compressed.jpg
  3. # High quality example settings
  4. jpeg-recompress --quality high --min 60 image.jpg compressed.jpg
  5. # Slow high quality settings (3-4x slower than above, slightly more accurate)
  6. jpeg-recompress --accurate --quality high --min 60 image.jpg compressed.jpg
  7. # Use SmallFry instead of SSIM
  8. jpeg-recompress --method smallfry image.jpg compressed.jpg
  9. # Use 4:4:4 sampling (disables subsampling).
  10. jpeg-recompress --subsample disable image.jpg compressed.jpg
  11. # Remove fisheye distortion (Tokina 10-17mm on APS-C @ 10mm)
  12. jpeg-recompress --defish 2.6 --zoom 1.2 image.jpg defished.jpg
  13. # Read from stdin and write to stdout with '-' as the filename
  14. jpeg-recompress - - <image.jpg >compressed.jpg
  15. # Convert RAW to JPEG via PPM from stdin
  16. dcraw -w -q 3 -c IMG_1234.CR2 | jpeg-recompress --ppm - compressed.jpg
  17. # Disable progressive mode (not recommended)
  18. jpeg-recompress --no-progressive image.jpg compressed.jpg
  19. # Disable all output except for errors
  20. jpeg-recompress --quiet image.jpg compressed.jpg

jpeg-compare

Compare two JPEG photos to judge how similar they are. The fast comparison method returns an integer from 0 to 99, where 0 is identical. PSNR, SSIM, and MS-SSIM return floats but require images to be the same dimensions.

  1. # Do a fast compare of two images
  2. jpeg-compare image1.jpg image2.jpg
  3. # Calculate PSNR
  4. jpeg-compare --method psnr image1.jpg image2.jpg
  5. # Calculate SSIM
  6. jpeg-compare --method ssim image1.jpg image2.jpg

jpeg-hash

Create a hash of an image that can be used to compare it to other images quickly.

  1. jpeg-hash image.jpg

jpeg-zfpoint

Compress JPEG files by re-encoding them to the lowest JPEG quality using the peculiarity jpeg (zero point) quantization feature.

webp-compress

Compress JPEGs by re-encoding to the smallest WEBP quality while keeping perceived visual quality the same.

This is a lossy operation, but the images are visually identical and it usually saves >50% of the size for JPEGs coming from a digital camera, particularly DSLRs.

All EXIF/IPTC/XMP and color profile metadata are not preserved!

Some basic photo-related editing options are available, such as removing fisheye lens distortion.

Building

Dependencies

Debian

Debian users can install via apt-get:

  1. sudo apt-get install build-essential autoconf pkg-config nasm libtool libjpeg8-dev
  2. git clone https://github.com/ImageProcessing-ElectronicPublications/libiqa.git
  3. cd libiqa
  4. make
  5. sudo make install
  6. cd ..
  7. git clone https://github.com/ImageProcessing-ElectronicPublications/libsmallfry.git
  8. cd libsmallfry
  9. make
  10. sudo make install
  11. cd ..

Compiling (Linux and Mac OS X)

The Makefile should work as-is on Ubuntu and Mac OS X. Other platforms may need to set the location of libjpeg.a or make other tweaks.

  1. make

Installation

Install the binaries into /usr/local/bin:

  1. sudo make install

License

All are released under an MIT license.

http://dgt.mit-license.org/