Get difference between two images as transparent image in GIMP

I have two images A and B which are similar in many regions.

I want to create an image C so that

B = C on top of A

where C should be as transparent as possible. on top of is the normal layer superposition.

So C is some kind of difference between A and B. If A and B are identical, then C is totally transparent. If A and B are very different, then their C would be nearly identical to B.


You could use the “difference” layer mode to create a layer mask, and apply it to B like this:

  1. Open both images as layers, A on the bottom, B on top
  2. On the layer’s dialog, mark B’s layer mode as “difference”. You now
    should see the image mostly black is the images are alike, with the
    colored areas marking the areas that are different. These colors,
    however, won’t match B’s colors as you want
  3. Edit->Copy visible, to get a copy of the calculated effect on B
  4. Duplicate Layer B, change it’s mode back to “Normal” (let’s call this layer C)
  5. On the Layers menu, add a layer mask to C (Layer->Mask->Add Layer Mask).
  6. With the mask selected, paste the contents copied in step 3 (edit->paste).
  7. Anchor the pasted contents on the layer’s mask (layer->Anchor layer)

There you are – make Layers A and B invisible, and you should be very close to what you want. Further operations on the layer mask (I recommend using Colors->curve) can adjust the opacity/transparency of the areas on layer C.

update I recently answered a similar question to this on Stackoverflow, where the OP wanted to perform the task programatically (Using Python + Python-imaging-library) – I’ve posted the full program on that question and it might be of help for anyone interested in this answer.

Source : Link , Question Author : cheesus , Answer Author : Community

Leave a Comment