I have a shadow on a solid coloured background. I know that the colour of the shadow is black (#000000), and I know exactly what the background colour is.

How can I remove the colored background and convert the shadow into a black image with alpha?

Given that I know what the colour of the shadow is the problem should be exactly solvable for an alpha-shadow that gives me back the original image when I overlay it on the background colour.

Using paint.NET, or Gimp, or any other free software. I can find lots of approximate solutions, that "work" even when the colour of the shadow is not known (Leaving some of the background colour "lingering" in the result), but I don't want that. I want the exact solution when I do know the colour of the shadow and the background.

  • Have you tried GIMP's Color to Alpha?
    – Billy Kerr
    Commented Jan 22, 2018 at 8:27
  • 1
    No single step / tool will be sufficient solve the problem, because you somehow have to give the image manipulation program the "information" that the color of the shadow is black, not just what the color of the background is. Without knowing that it can't solve for the alpha, it can only make a best guess... one which isn't exactly correct. That's what I'm missing, is the way to give it that information. Commented Jan 23, 2018 at 7:48
  • 1
    In that case what you should have done is create your shadow as a layer on its own, so that you don't have to extract it. You are trying to edit an existing flat image without layers, sadly the approximation of Color to Alpha or similar techniques will have to do. Removing backgrounds from flat images is always an approximation, and will require the use of an alpha mask of some kind, no matter what software you use.
    – Billy Kerr
    Commented Jan 23, 2018 at 8:13
  • "What I should have done" is entirely irrelevant and unhelpful. And furthermore it absolutely doesn't "have to do", I literally know the formula that I could use to implement this... there's four variables, and I know three of them, there IS an exact solution. It's simply a problem of finding a tool / process that solves for it. Commented Feb 4, 2018 at 5:52

1 Answer 1


I don't know GIMP very well, but the method should be the same as in Photoshop. (All the screenshots are from Photoshop.)

You need to make use of the divide blend mode (which is apparently called layer mode in GIMP).

  • We start out with a grayscale image, to which I have multiplied a colored background.

    Grayscale image. Colored background.

  • Create a new layer on top of the image, filled with the image's background color.

  • Set the blend mode/layer mode of the color layer to divide.

    After dividing with color. Divide blend mode.

    This removes the color from the image and leaves it with a white background.

  • Flatten the image.

  • In Photoshop it seems to work perfectly, but in GIMP the lightest color becomes (254, 254, 254)! So if you are using GIMP you need to use something like Levels to lower the white point by 1.

  • Invert the image.

  • Use the inverted image as Layer Mask for a completely black layer.

    Image with transparency. Inverted image as layer mask.

  • Now, you have a black image with a transparent background.

  • This is what I mean though, this is another approximate solution. The result is clearly more translucent than it should be compared to the original image, that is, if you overlay it back on the original background color it won't look the same as the original. What I want to do is separate the image into two parts, the background color and a shadow overlay, which produce EXACTLY the original image when recombined. I know this is mathematically possible, I could write a C program to do it, what I want to know is how to do it in an image editing program. Commented Jan 23, 2018 at 2:13
  • @Mark, you are probably right. With this exact background color (RGB 130,170,160) it worked perfectly in PS - I have compared to the original image. But it doesn't seem to work with all background colors ...
    – Wolff
    Commented Jan 23, 2018 at 14:20

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