Reconstructing opacity values in a scanned image

I’ve got several scanned images that were originally produced from transparencies that had varying opacity at different points. They weren’t just solid pictures with fully transparent backgrounds like animation cels.

I’d like an automated way to construct new PNG images with the original opacity levels intact. I have a bunch of images to do, with a few examples of each image with different flat background colors.

It seems to me someone else has probably already encountered this and solved it with software, where one can dump two or three versions of the same image with different backgrounds into some manipulation algorithm and have it spit back out a PNG or some other format with the right opacity levels in the translucent parts.

My google-fu has failed me on this, though. Everything I found when searching was how to convert the flat backgrounds into fully transparent parts, which I had already figured out on my own in 5 minutes poking around in Gimp.

If the images were originally produced from transparencies, then anything that was originally white should be transparent, no? And anything which is a partially-white shade should be partially transparent. I don’t think you’d need multiple backgrounds, just a single white background (which is probably how they were scanned anyway).

If I had only one example, e.g. a single one scanned on a white background, I wouldn’t be able to tell if a grey pixel is grey because the original spot was opaque and grey, or was the original spot black and translucent.

By comparing two examples, say I have the same original transparency that was scanned on a green background, I could compare the two pixels between the images. If they’re the same color, that’s an opaque spot. If they’re different, that spot was translucent or transparent. They end up being different colors depending on what the background color was.

I’m pretty sure there’s some mathematical formula that could compare the RGB values of the same spot in two or maybe more examples are required and figure out what its original color and translucency values were.

To be clear, by “transparencies”, you mean things that were meant to be put on an overhead projector, and viewed by means of the image projected onto a screen? Because those things will not have any opaque white dye at all, since anything opaque on the transparency slide (no matter what its color) will show up as black on the screen. Likewise, they won’t have any grey, but instead partially-transparent black.

I believe they were originally intended to be photographed against flat matte backgrounds, and occasionally superimposed over one another, with parts showing through. I might be using the wrong terms to describe them.

This should be doable in principle if you have the same foreground superposed with the same opacity on two different known background images. Basically, the difference between the two final images should be proportional to the difference between the two background images; the proportionality factor for each pixel should be one minus the opacity of the foreground for each pixel. By this procedure you could construct an array of opacities for each pixel, and then use that array to reconstruct the original image.

But as to implementing this, I haven’t a clue. I could probably do it in Mathematica given an afternoon, but there’s probably better tools for it out there.

Oh, that sounds like animation cels, then. Yeah, in that case, you could have opaque colors, and you would need multiple backgrounds to be sure. What MikeS said should work, though I think you might actually need three different backgrounds (or at the least, two backgrounds that are perfectly complementary-- Pure white and pure black are probably best). You’d also have to be careful about image alignment, if you’re using that technique.

Gimp is definitely the right tool for the job, but it’s got a steep learning curve. Unless you can find a step-by-step procedure for this online, or already have enough Gimp mastery to write the step-by-step yourself, it’ll take a long time to figure it out.

I hope so. You described pretty well what I’d intuitively deduced was possible, but perhaps didn’t explain all that well in my OP.

Image alignment is perfect; I think someone before me already did that task.

That’s what I’m hoping to find.

It occurred to me that if I had the original physical transparency in hand, and I only had an ordinary flatbed scanner to use, I would need something like this procedure to get the equivalent PNG with a proper alpha channel for the translucent areas. So somebody somewhere perhaps has already written the software or Gimp/Photoshop steps necessary.

You’re not kidding about Gimp’s learning curve; I definitely need hand-holding to get this done.

Are you comfortable with command-line programs? I don’t know the exact commands, but I’m almost certain that ImageMagick could do this. Possibly this tutorial will get you going. If you put a known background pattern behind the transparency, then you can maybe use that process to find the transparency mask.

Thank you, thank you, this is exactly what I was looking for.

I wasn’t quite so sure when I started reading the section you linked, because it talked about removing the background and manually inserting graded translucent sections to make up for the now-missing original translucent areas, and other things that were similar, but not exactly my situation. But then I got down to this section.

Bingo.

Thanks, everybody, now I just need to learn how to use ImageMagick®, which is thankfully free.

There’s also an image-manipulation program called Curvemeister that exists largely for the purpose of fixing up image color problems. I know exactly zilch about it, except that it appears to be sophisticated. It’s not free. But the web site opens with an impressive looking slide show of color-fixed images.