Gimp-Forum.net
Extracting Identical Pixels Between Two Layers - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions)
+--- Thread: Extracting Identical Pixels Between Two Layers (/Thread-Extracting-Identical-Pixels-Between-Two-Layers)



Extracting Identical Pixels Between Two Layers - saltasaurus - 12-15-2023

Hello, I am trying to cut out or isolate in some fashion all of the pixels that are identical between two images. These two images are different coloured variants of each other, and certain pixels are identical. 

I was thinking of putting them into two layers and... I don't know lol. Just wondering if there is an easy way to go about this. 

Note that I am NOT trying to delete these pixels. In the end, I would like to put them onto a layer on their own.


RE: Extracting Identical Pixels Between Two Layers - Ofnuts - 12-15-2023


  1. Align the layers
  2. Put the top one in "Difference" mode: identical pixels in both layers will yield a perfectly black result.
  3. Do Layer > New from visible to snapshot this into a  new layer
  4. Use the Threshold tool to set to white any pixels that is not perfectly black, to obtain an image where all white pixels correspond to different pixels in the compared images
  5. If you want a selection from this, open the Channels list, right click on any R/G/B channel and "Channel to selection". You can then hide/discard the Visible layer.
[attachment=10866]



RE: Extracting Identical Pixels Between Two Layers - rich2005 - 12-15-2023

Another way

This is from here: https://graphicdesign.stackexchange.com/questions/27484/get-difference-between-two-images-as-transparent-image-in-gimp and sort of ties in with your other post.

The two images as layers
Using the bottom layer Filters -> Animation -> Optimize (Difference)
That makes a new image and the top layer has an alpha channel of the common pixels
Layer -> Mask -> Add Layer Mask -> Layers Alpha Channel

Then on the bottom layer using a script (attached) to copy the layer mask without going through the make / copy / paste / anchor routine.
Click in the layer mask to make active and invert it Colors -> Invert
If you just want that result, one way is Layer -> New from Visible.

Attached sg-copy-mask-from-above.zip Unzip and put sg-copy-mask-from-above.scm in your Gimp User Profile folder C:\Users\"yourname"\AppData\Roaming\GIMP\2.10\scripts

Another quick animation, using a very obvious magenta dots common pattern https://i.imgur.com/LHC7JDA.mp4