Slashdot Mirror


Choosing Better-Quality JPEG Images With Software?

kpoole55 writes "I've been googling for an answer to a question and I'm not making much progress. The problem is image collections, and finding the better of near-duplicate images. There are many programs, free and costly, CLI or GUI oriented, for finding visually similar images — but I'm looking for a next step in the process. It's known that saving the same source image in JPEG format at different quality levels produces different images, the one at the lower quality having more JPEG artifacts. I've been trying to find a method to compare two visually similar JPEG images and select the one with the fewest JPEG artifacts (or the one with the most JPEG artifacts, either will serve.) I also suspect that this is going to be one of those 'Well, of course, how else would you do it? It's so simple.' moments."

17 of 291 comments (clear)

  1. ImageMagick can give you EXIF data. by bcrowell · · Score: 4, Informative

    The ImageMagick package includes a command called identify, which can read the EXIF data in the JPEG file. You can use it like this:

    identify -verbose creek.jpg | grep Quality

    In my example, it gave " Quality: 94".

    This will not work on very old cameras (from ca. 2002 or earlier?), because they don't have EXIF data. This is different info than you'd get by just comparing file sizes. The JPEG quality setting is not the only factor that can influence file size. File size can depend on resolution, JPEG quality, and other manipulations such as blurring or sharpening, adjusting brightness levels, etc.

    1. Re:ImageMagick can give you EXIF data. by DotDotSlasher · · Score: 3, Informative

      imagemagick can also compare two images, and tell you how different they are. That is -- quantify the differences by returning a floating point number or two (PSNR, RMSE) in a way that a more-compressed JPEG image will return a correspondingly different floating point value. I know the question concerns two JPEG-compressed images, but if you do have an original image -- and you want to test which is closest to the original, ImageMagick can do that. Use the ImageMagick compare function.
      See http://www.imagemagick.org/script/compare.php

      Also, [[www.gimp.org]] is able to look at an image and approximate what JPEG compression quality setting was used, and use that same quality setting to save an output JPEG copy of the image. So -- they have some algorithm inside of their application which takes an image and returns (a good guess of) the corresponding jpeg quality value.
      Of course, this does not help you if the image was saved with a lousy JPEG quality value, like 10/100, and later saved at a much higher value, like 98/100. Since the algorithm only sees the last image, it would tell you the quality value is 98/100, even though the contents of the image would indicate the results of 10/100 compression, because of multi-generational lossy compression.

  2. Re:File size by Robotbeat · · Score: 4, Informative

    File size doesn't tell you everything about quality.

    For instance, if you save an image as a JPEG vs. first saving as a dithered GIF and _then_ saving as JPEG, then the second one will have much worse actual quality, even if it has the same filesize (it may well have worse quality AND have a larger file size).

  3. DCT by tomz16 · · Score: 4, Informative

    Just look at the manner in which JPEGs are encoded for your answer!

    Take the DCT (discrete cosine transform) of blocks of pixels throughout the image. Examine the frequency content of the each of these blocks and determine the amount of spatial frequency suppression. This will correlate with the quality factor used during compression!

       

  4. use a "difference matte" by Anonymous Coward · · Score: 4, Informative

    load up both images in adobe after effects or some other image compositing program and apply a "difference matte"

    Any differences in pixel values between the two images will show up as black on a white background or vise versa...

    adam
    BOXXlabs

  5. Try ThumbsPlus by Anonymous Coward · · Score: 3, Informative

    ThumbsPlus is an image management tool. It has a feature called "find similar" that should do what you want as far as identifying to pictures that are the same except for the compression level. Once the similar picture is found you can use ThumbsPlus to look at the file sizes and see which one is bigger.

  6. Found it a while ago by sco08y · · Score: 5, Informative

    I mean, you don't want second rate pictures in your pr0n stash?

    I had problems building it back then, let alone writing the scripts for it and the hassle of figuring out which images were duplicates, but this utility seems to fit the bill.

  7. image quality measures by trb · · Score: 4, Informative
    google (or scholar-google) for Hosaka plots, or image quality measures. Ref:

    HOSAKA K., A new picture quality evaluation method.
    Proc. International Picture Coding Symposium, Tokyo, Japan, 1986, 17-18.

  8. Re:File size by Shikaku · · Score: 4, Informative

    http://linux.maruhn.com/sec/jpegoptim.html

    No. You can compress JPEG lossless.

  9. Re:Filesize is a hint by thethibs · · Score: 4, Informative

    More Noise = Less Compression

    --
    I'm a Programmer. That's one level above Software Engineer and one level below Engineer.
  10. Re:File size by Score+Whore · · Score: 5, Informative

    ...THERE IS NO LOSSLESS JPEG. PERIOD.

    Except for Lossless JPEG standardized in 1993. But other than that, no there is no lossless jpeg.

  11. Look at the DCT coefficients by uhmmmm · · Score: 3, Informative

    JPEG works by breaking the image into 8x8 blocks and doing a two dimensional discrete cosine transform on each of the color planes for each block. At this point, no information is lost (except possibly by some slight inaccuracies converting from RGB to YUV as is used in JPEG). The step where the artifacts are introduced is in quantizing the coefficients. High frequency coefficients are considered less important and are quantized more than low frequency coefficients. The level of quantization is raised across the board to increase the level of compression.

    Now, how is this useful? The reason heavily quantizing results in higher compression is because the coefficients get smaller. In fact, many become zero, which is particularly good for compression - and the high frequency coefficients in particular tend towards zero. So partially decode the images and look at the DCT coefficients. The image with more high frequency coefficients which are zero is likely the lower quality one.

  12. Re:AI problem? by arose · · Score: 5, Informative

    AI or small utility... You never know with computers ;)

    --
    Analogies don't equal equalities, they are merely somewhat analogous.
  13. Re:AI problem? by bendodge · · Score: 5, Informative

    Since the mods haven't noticed, and I don't have mod points, let me point out that THIS POST HAS THE ANSWER. A real program that will do what the asker wants. The source is available, but I can't seem to find its license (it includes some of the Independent JPEG Goup's code). Also, doesn't a jpeg's EXIF data or some other tag in the file tell you what quality it was saved at?

    --
    The government can't save you.
  14. Re:File size by Binary+Boy · · Score: 4, Informative

    Lossless JPEG and lossless JPEG2000 are both exactly that - lossless. Not perceptually lossless, which is what people often use to refer to high-quality, lossy JPEG/JPEG2000, or JPEG-LS. Lossless JPEG uses a PCM-like encoder, not DCT, AFAIR. Lossless JPEG and lossless JPEG2000 are, in fact, lossless, at least with regards to image data in supported color spaces. This is in part a result of *not* converting to YCrCb, since that conversion is lossy, of course. Not all Lossless JPEGs are 8bit YCrCb.

    Accusoft, for one, has a toolkit for building lossless JPEG applications which supports 16bit RGB and greyscale lossless JPEG modes.

    The near-lossless JPEG you're thinking of is JPEG-LS, which is perceptually lossless, and guarantees a maximum error rate that is generally neglible for almost all applications. This format gets better compression ratios than Lossless JPEG, of course.

    Neither the lossless or near-lossless JPEG modes are common though, outside of niche apps. Lossless JPEG2000 is, however, since almost all JPEG2000 libraries support it alongside the lossy modes.

  15. Re:AI problem? by bh_doc · · Score: 3, Informative

    http://www.jhnc.org/findimagedupes/

    There's a bunch, but I know you can construct command line operations with this one. I imagine you could construct a system from this and the parent program that will find dupes, then nuke the poorer quality of each, or whatever.