Serene Life

by garik

submit your photo


Hall of Fame
View past winners from this year

Please participate in Meta
and help us grow.

Take the 2-minute tour ×
Photography Stack Exchange is a question and answer site for professional, enthusiast and amateur photographers. It's 100% free, no registration required.

For example, for a recent conversation about JPEG compression I wanted to compare pixel for pixel what changed between two JPEGs (one with compression level 100, and one with compression level 95).

How do I generate good visual maps of what changed without tedious custom software programing?

share|improve this question
2  
Not submitting this as an answer as it's probably not a viable solution for photos, but GitHub (a programmer's site) has some interesting ways of comparing images: github.com/cameronmcefee/Image-Diff-View-Modes/commit/… Try clicking "2-up", "Swipe", "Onion Skin" and "Difference". –  Henrik N May 6 '11 at 12:19

5 Answers 5

up vote 23 down vote accepted

Photoshop + Layers FTW. (yes, you can also use the Gimp, or any other editing software with the same functions.)

Start with your base image, in the case above, I used the jpeg quality 100 image.

  1. create a new layer atop it
  2. paste the second image into that layer
  3. set the layer style to "difference"
  4. create an effect layer atop that
  5. set the effect to threshold
  6. set the threshold value to 1

In the resulting image, any pixel that is any any way different between the two images will be white. You can adjust it to allow things to be "a little different" by altering the threshold value.

Example showing a LOT of difference between jpeg 92 and 100 from Lightroom. comparing jpeg 92 and 100 from LR with photoshop layers

Example showing no difference at all between 95 and 100. comparing jpeg 95 and 100 from LR with photoshop layers

Not that's just showing a binary "changed or not", what if you wanted more detail on how much it changed, say by color channel?

  1. Replace the threshold adjustment layer with a curves adjustment layer.
  2. edit the curve
  3. turn on show clipping
  4. grab the input white handle below the lower right corner and drag it over to the left, as far as you can go
  5. slowly move back to the right until you don't see any clipping (the preview image is all black)
  6. turn clipping back off and save the curve change

The brighter the resulting pixels, the more they're different in that color. The downside though is you end up with a lot of grey mud... so sometimes it's easier to just threshold it to see where differences are. That's why I build both and toggle which one is visible.

more descriptive view of the difference

share|improve this answer
1  
You should mark this as the accepted answer for its pure awesomeness. ;) –  jrista Dec 23 '11 at 20:19
    
well, if you insist.... ;) (thanks for reminding me I hadn't accepted one.) –  cabbey Dec 27 '11 at 7:01

If you use Photoshop, here's how I'd do it:

Put the two jpegs in the same psd file, in two separate layers. They should overlap exactly, since their dimensions are the same. (which one goes on top doesn't matter).

Set the layer blending mode to "Difference." You'd see a mostly black result. Depends on the quality difference between the two original layers you may see more or less of the noise.

enter image description here

share|improve this answer
    
Difference alone doesn't really help much when you're left with a big black void like that. :) –  cabbey May 6 '11 at 7:15
    
@cabbey sure, comparing 100% to 95% you most likely will get a solid black. But that's what your question was asking isn't it? In your owner answer, you're changing the values from the originals being compared, which makes them no longer having the original compression settings. –  Jin May 6 '11 at 7:20
    
You get virtually solid black on just about any comparison, because the differences are so small. The threshold/curve layer after the difference doesn't do anything to the compression settings, it just aids the visualization of the lower bounds of that black soup that difference prepared. (I'm not 100% sure what you meant by that, so I could be heading off in a different direction there....) –  cabbey May 6 '11 at 7:31
    
@cabbey if you're asking for a pure bit-wise operation of the difference between the 2 images, then "Difference" blending mode alone gives you that. When you adjust threshold/curve, though the result is more obvious to the naked eye, but it's not an accurate representation of what has changed. When do you that, you're not longer comparing a 100% to a 95%. –  Jin May 6 '11 at 7:36
    
Sure you are. The level of compression stopped mattering the second photoshop loaded the image from disk into it's internal buffers, it is now an uncompressed pixel array in memory... if those pixels got there because the image had a square blob there or because they are an artifact of the compression level is not relevant. –  cabbey May 6 '11 at 7:42

All image processing packages should make this easy. I'll show you how to do it in Mathematica, if you have access to this system. Mathematica is a programming language, but it's really easy to do these kinds of manipulations, so if you have access to it (e.g. through a university site license), I recommend you give it a go!

First, import the image:

img = Import["http://farm1.staticflickr.com/62/171463865_36ee36f70e.jpg"]

Recompress it using JPEG compression

img2 = ImportString@ExportString[img, "JPEG", "CompressionLevel" -> 0.35]

Mathematica graphics

Now take the difference of pixel values, converting them first to floating point numbers to ensure that negative values are preserved.

diff = ImageSubtract[Image[img, "Real"], Image[img2, "Real"]]

Mathematica graphics

Not much is visible on the difference image (the difference is tiny), and negative values are clipped to black. So let's rescale all values to fill the whole dynamic range (the minimum will be scaled to 0, the maximum to 1):

ImageAdjust[diff]

Mathematica graphics

ImageDifference gives the absolute difference of the two images, and produces no negative numbers. This is the operation you are more likely to find in image processing packages, especially GUI ones (Photoshop, GIMP).

ImageDifference[img, img2]

Mathematica graphics

We can also take a single RGB channel, for example the red one, and visualize the positive and negative differences using 'opposing' colours:

ArrayPlot[0.5 + ImageData[First@ColorSeparate[diff, "Red"]], 
 ColorFunction -> "RedGreenSplit", ColorFunctionScaling -> False]

Mathematica graphics

Here's the same thing, with the differences amplified 5 times. The JPEG artefacts are more recognizable now.

ArrayPlot[0.5 + 5 ImageData[First@ColorSeparate[diff, "Red"]], 
 ColorFunction -> "RedGreenSplit", ColorFunctionScaling -> False]

Mathematica graphics

The advantage of using a programming language is that we can easily automate this and see how the difference changes for "compression levels" between 0.1 and 1.0:

Grid@Partition[Table[
   ArrayPlot[
    0.5 + ImageData[
      First@ColorSeparate[
        ImageSubtract[Image[img, "Real"], 
         Image[ImportString@
           ExportString[img, "JPEG", "CompressionLevel" -> c], 
          "Real"]], "Red"]], ColorFunction -> "RedGreenSplit", 
    ColorFunctionScaling -> False],
   {c, 0.1, 1, 0.1}
   ], 5]

Mathematica graphics

share|improve this answer
    
Its always good to see a scripted/automated option! :) –  jrista Aug 8 '12 at 18:22

GitHub has some interesting image diff tools built into it on the web, as described here and demonstrated in this demo.

share|improve this answer
  1. Open one of the images in GIMP or Photoshop.
  2. Add the second image as a new layer on top of the first one.
  3. Set the blend mode of the top layer to "Difference"

In the resulting image the black parts show where the original images are identical and anything lighter shows differences.

share|improve this answer
    
Difference alone doesn't really help much when you're left with a big black void like that. :) –  cabbey May 6 '11 at 7:15
    
You can always adjust the levels on the resulting image. Whenever I've used this technique I've had pictures different enough to be able to see the changes :) –  Dan May 6 '11 at 10:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.