: 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
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.
More posts by @Sue6373160
3 Comments
Sorted by latest first Latest Oldest Best
GIMP has a brush mode named "Color erasing". Applying this brush, colored with color X, to definite pixel P1 creates a pixel P2 with lowered alpha channel, the way that blending P2 with pixel with color X in normal mode results pixel P1. Same effect, applied to selected region or whole image can be achieved using "Color to Alpha" action.
Brush mode could also be applied to "Clone tool". In this case it is possible to take color from pixels of background image A and apply it to corresponding pixels of result image B. Image that has left is desired image C.
In details creation of image C is the following:
Put images A and B as layers (A below B).
Duplicate image B and call it C.
Put it between A and B.
Hide image B.
Choose "Clone Tool".
On "Tool options" pane set following options:
Mode: "Erase color";
Brush: use sharp round brush ("Hardness 100")
Size: make brush larger to easily paint all the image at once.
Select A layer and CTRL + on top left pixel to
select a place from which to clone and remember its position
(for 100% zoom it will be (1,1), for 50% it will be (2,2) etc).
Now select layer C and start painting from the top left and cover
all the image without lifting the brush. It may seem that image
does not change. But if you hide layer A, you'd see that layer C
now contains desired image.
Check result:
Show layer A and layer C.
Toggle layer B visibility to be sure that images look the same.
(You could also choose Mode "Difference" for layer B, in such
case you should get absolutely black image.)
Note: This method works as described if background image is opaque.
On transparent parts of background image, blending C on the top of A
looks different from image B.
There is a simple method to do it:
Open the images as two layers, run Filters - Animation - Optimize (Difference), you should get the same resulting image that is now made of the bottom layer and a diff layer on top of it.
The things get complicated only if you have partial transparency, because the filter removes it.
Here is a workaround I've found for this case:
Remove Alpha Channel on both layers (the action is in the context menu)
The images will receive white background, but don't worry, we'll undo it later.
Filters - Animation - Optimize (Difference)
Now we have the difference layer with white background in places of partial transparency, but we need those pixels to be transparent, so we'll take the shape of the diff and copy the image of this shape from the original top layer. Ensure the newly generated diff layer is selected and continue:
Layer - Layer to Image Size
Edit - Copy (Ctrl+C)
Return to the original image
Undo, Undo to return transparency to our layers
Edit - Paste as - New Layer
Alpha to Selection (in the context menu) on the pasted diff layer
Delete the pasted diff layer
Ensure that the top layer is selected and Copy (Ctrl+C) from it
Now you have the diff, just Paste (Ctrl+V) it and create a new layer from it.
Of course, no magic happens, and the partially transparent top layer won't alter colors or reduce transparency of the bottom layer, so it's only for cases of extension, where the altered pixels of the top layer cover the bottom layer.
P.S. jsbueno's method didn't work out for me.
You could use the "difference" layer mode to create a layer mask, and apply it to B like this:
Open both images as layers, A on the bottom, B on top
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
Edit->Copy visible, to get a copy of the calculated effect on B
Duplicate Layer B, change it's mode back to "Normal" (let's call this layer C)
On the Layers menu, add a layer mask to C (Layer->Mask->Add Layer Mask).
With the mask selected, paste the contents copied in step 3 (edit->paste).
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.