0

Like explained here: Making the background of an image transparent in Gimp

But via CLI! I'm using Gimp on Ubuntu, and I would like to do this on a bunch of images.. Even if it doesn't do a perfect work obviously..

1
  • 2
    There are thousands of tutorials on youtube for GIMP
    – Billy Kerr
    Commented Dec 26, 2017 at 22:58

2 Answers 2

1

Gimp is likely overkill (and is a pain to work with for batch...). Although ImageMagick has no color-to-alpha operation, someone came up with a "formula" that works very well:

convert in.png \( -clone 0 -fill "#55f883" -colorize 100 \) \( -clone 0,1 -compose difference -composite -separate +channel -evaluate-sequence max -auto-level \) -delete 1 -alpha off -compose over -compose copy_opacity -composite out.png

Where #55f883 is your background color. Replace convert with magick convert in recent versions.

ImageMagick is the imagemagick package in your distro.

0

The problem of removing the backgrounds and leaving the essential objects intact automatically or with a couple of clicks is still unsolved. Surely there are propellerheads who have done serious math and programming efforts to find something useful to help the background removal, but the best semiautomatic tools still are the selection tools, which select uniformly enough colored areas or follow an edge which is pointed coarsely with the mouse cursor.

So, if these tools + fully manual erasing and clipping path drawing are not enough, you are out of luck. The REAL magic wand still waits its inventor.

ADD due the comment:

If one knows before taking the photos that the backgrounds must be removed, he takes the photos in front of uniform backgrounds - your green screen behind the target is a common solution. If the target gets all light from white lamps, nothing from the single color background and the background color is nonexistent in the target, then the background removal can be automated. That's done in movie editing software which must process hundreds of images in seconds. Surely it's also programmed as scripts for photo editing software, but I have not such script.

In GIMP there's a tool which changes a selected color to transparency. It's Colour to alpha. For good result the selected color must be fully saturated.

I have taken hundreds of photos and removed their backgrounds in the following way for printed catalogs:

Take 2 photos keeping all absolutely in the same place (=a sturdy camera stand, timed shooting). The first photo has all lights on, the second photo has only uniformly lighted bright background, but the target is in the dark.

The black silhouette and white background have high contrast. One click with the magic wand selects the background easily. The selection is used to delete the background in the full light image, which is placed into another layer.

The 2 photo method does not work for alive targets, but it is not dependent on target colors and can be easily done with modern large led panels which are the background; one is needed also under the target.

The black silhouette needs often some minor tweaks, so this method isn't easily automatized.

2
  • 1
    What if I shot all images in the same place with the same green background? Can this help?
    – Cirelli94
    Commented Dec 26, 2017 at 22:38
  • @Cirelli94 there's more data.
    – user82991
    Commented Dec 26, 2017 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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