Author Topic: Are there any graphics apps that can remove backgrounds or compare pixels?  (Read 14233 times)

0 Members and 1 Guest are viewing this topic.

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3768
Hey, folks, does anyone know of any applications, or functions in existing ones like GIMP or Paint Shop Pro or Photoshop, that can easily handle these scenarios?

---

1. Background removal


Let's say I have something like the two screenshots above: one with foreground elements as well as the background, and another with only the background.
Can I subtract any pixels that match, essentially removing the background, to get an output of only the unique pixels from the first screenshot?

I know there are background removal tools online as well as apps that can do that, though those are usually suited for photos, and usually higher-res.
I don't believe they would work well with low-res pixel art, like screenshots, especially when background colours might be as vibrant as foreground elements.

Keep in mind that this is an example, I know that for Super NES emulation, and a few other platforms, it is possible to disable various background and/or sprite layers.
What I'm thinking of could be handy for isolating sprites in computer games (like '90s point-and-click adventure games), or if I only have existing screenshots on hand.

---

2. Pixel comparison


Another function that could also work if we're comparing pixels could be just simply identifying pixels that are the same or different across screenshots of the same size.
I'd like to take two screenshots, and get an output like that third image there, simply a two-colour image, with green showing the alike pixels and red showing the differing pixels.

Or, whatever colour.  It could be black and white, doesn't matter.

This would make it easy to identify differences in similar images (like if I need to check versions of a pixel art image in progress).
I'm sure image masks could be made of that to isolate things (such as sprites, though that'd be similar to the earlier example).

I just had a thought... one could take a screenshot of a point-and-click adventure game before any items are picked up, then pick up all the items on screen and take another screenshot, and the resulting output image would be silhouettes of all the items.
Select just the red, float it, expand it by one pixel, paste the original output so that the expansion becomes an outline, stick that on the original screenshot, and boom, we've outlined all the items!  Or all the changeable/interactable elements.
Could certainly be handy for stuff like that.

---

So, does anyone know of any applications or easy methods to do the functions I described above?  Please and thanks in advance for any help.

Offline G.E.R.

  • Jr. Member
  • **
  • Posts: 93
Re: Are there any graphics apps that can remove backgrounds or compare pixels?
« Reply #1 on: February 02, 2025, 02:57:01 am »
For pixel comparison it's very simple:
You should to make one layer on negative (Image - Adjustments - Invert), set transparent 50% (Opacity 50% on layer-menu) and place this layer on top of the first layer. The same pixels will be gray, the difference pixels will be another colors. Another way: just set blend mode Difference on top layer.


For background removal: I never used it, but you can merge previous layers and select background, move selection to the first image and copy area on new layer.

You can see all of this in this example

Offline VGCartography

  • Jr. Member
  • **
  • Posts: 53
Re: Are there any graphics apps that can remove backgrounds or compare pixels?
« Reply #2 on: February 03, 2025, 08:38:29 am »
Here's a python function that will do it, given two input images and an output path (black for matching areas, red for different):

Code: [Select]
from PIL import Image
import numpy as np

def compare_images(image_path1, image_path2, output_path):
    img1 = Image.open(image_path1)
    img2 = Image.open(image_path2)
    if img1.size != img2.size:
        raise ValueError("Images must be the same size.")
   
    # Convert images to numpy arrays
    arr1 = np.array(img1)
    arr2 = np.array(img2)
    if arr1.shape != arr2.shape:
        raise ValueError("Images must have the same number of channels.")
   
    # Find where pixels are the same (set to black) and different (set to red)
    diff = np.zeros_like(arr1)
    mask = np.any(arr1 != arr2, axis=-1)  # True where pixels differ
    diff[..., 0] = mask * 255  # Red channel
    diff[..., 1] = 0           # Green channel
    diff[..., 2] = 0           # Blue channel
   
    # Convert back to image
    output_img = Image.fromarray(diff)
    output_img.save(output_path)

Offline mechaskrom

  • Jr. Member
  • **
  • Posts: 57
Re: Are there any graphics apps that can remove backgrounds or compare pixels?
« Reply #3 on: February 24, 2025, 12:14:25 pm »
I have made a paint.net plugin that compares all visible layers below the selected layer. The result is drawn to the selected layer (transparent=same, magenta=different).
https://www.mediafire.com/file/1hititv1zm1uhon/DiffLayers.zip/file

You can then use the magic wand selection tool to only select the different parts and copy/cut or color fill them to do the functions you're looking for.

Paint.net also has built-in functions to blend layers in different ways (xor, difference) to achieve a similar effect.
Some tools and other stuff I've made:
https://github.com/mechaskrom

Offline JonLeung

  • Administrator
  • *****
  • Posts: 3768
I have made a paint.net plugin that compares all visible layers below the selected layer. The result is drawn to the selected layer (transparent=same, magenta=different).
https://www.mediafire.com/file/1hititv1zm1uhon/DiffLayers.zip/file

Apparently I forgot to say thanks, as the tool did come in handy when making maps for Beyond Shadowgate (PC).

Thanks, mechaskrom!

Or rather, it came in handy to fuel my obsession with getting all the possible states that a room could look like, but maybe I won't actually show them all.

Context: while I rarely make my own maps, I did make maps for this game while putting togther my "Beyond Shadowgate: Unboxing & Review" video on my "JonLeung1" YouTube channel.

I do plan on releasing another version of the maps that would be marked, but I likely won't be indicating EVERYTHING on them, just some stuff of interest like missable rooms (of which there are only a few), where the branch for the best/worst endings is, that sort of thing.  It's more a question of wording and formatting.

I might also do an "Screens" collage with all variations of all rooms, similar to what zagato blackfist did for the NES versions of Shadowgate, Deja Vu, and Uninvited.

But perhaps it's ludicrous to show EVERY possible state that EVERY room could be in.  Maybe two will be sufficient.

Still, all my quitting-and-reloading and picking up items in a different order just to get every one of these combos was time-consuming.  I didn't use mechaskrom's plugin as much as I should have, as it worked well enough the few times that I did, to spot differences between pixels, if I needed to recreate a scene in paint.net by changing some items around, instead of trying to get it in the game just right.

Thanks again!   :D