Fading two images together

I’m trying make a video that includes a transition where one image fades into a different image. I would like to do this programmatically (as opposed to using GIMP or video software) so that the result is repeatable and shareable. My starting point is a set of Gadfly plots that I saved out as PNG and then combine into a video with ffmpeg. So the fading could potentially be done either at the plotting stage before saving the images, or after.

Does anyone have any suggestions? Thanks in advance for any help!

You could plot the images with transparency (alpha=0.8) in plots. Reduce the transparency in one image as you increase in the other, plotting both at the same time, during the transition períod.

1 Like

It would take a fair bit of work for me to convert the plots I have from Gadfly to Plots, but I might switch them over if there is not a clear path forward with just working with Gadfly or the resultant images. But something like you suggest was my initial plan.

Presumably gadfly can also do transparency?

There are alpha keywords available. Though I don’t think there is a plot-wide parameter that would fade everything at once and some of plot elements don’t appear to accept alpha values (at least from my reading of the docs).

Is it really better to use transparency here? Isn’t the right approach simply to mix the two images like

img = (1-a) .* img1.+ a .* img2

?

Maybe I have a major misapprehension about alpha and transparency, but I imagine it just mixes in the background rather than representing some inherent property of the foreground.

3 Likes

Ooooh, that works beautifully! I guess I never really thought too much about the difference between transparency versus simple image math. Thanks a lot!

Note that this only works if gamma is 1.

1 Like