7
$\begingroup$

I'm not sure how to get a "fade in" effect.

$\endgroup$
2
  • 2
    $\begingroup$ Is this question or some variant of it relevant/useful? $\endgroup$
    – kglr
    Commented Jul 4, 2012 at 21:18
  • $\begingroup$ @kguler Thanks. I think it's useful, but a different question. $\endgroup$
    – M.R.
    Commented Jul 5, 2012 at 3:30

2 Answers 2

12
$\begingroup$

Start from understanding and setting up an transition functions sequence:

Plot[Evaluate@Table[(1 + Tanh[tr (x - dt n)])/2, {n, 1, Length[imgs], 1}], {x, 0, 
  dt (Length[imgs] + 1)}, PlotStyle -> Thick]

enter image description here

Set your images as a list:

enter image description here

Set 2 main parameters of your animation:

tr = 1;(* transition speed *)
dt = 4;(* display time *)

Finally use interactive interface

Animate[Overlay[Table[SetAlphaChannel[imgs[[n]], (1 + Tanh[tr (x - dt n)])/2], {n, 1, 
    Length[imgs], 1}]], {x, 0, dt (Length[imgs] + 1), 
  ImageSize -> Small}, AnimationRate -> 2]

enter image description here

Or make a table and export as an .GIF image

gift = Table[Overlay[Table[SetAlphaChannel[imgs[[n]], (1 + Tanh[tr (x - dt n)])/2], {n,
       1, Length[imgs], 1}]], {x, 0, dt (Length[imgs] + 1), 
    dt (Length[imgs] + 1)/50}];

Export["MyVacationSlideShow.gif", gift]
$\endgroup$
5
  • $\begingroup$ You don't necessarily have to use the hyperbolic tangent; any number of "sigmoidal" functions ought to do the trick... $\endgroup$ Commented Jul 5, 2012 at 2:22
  • $\begingroup$ Lovely answer Vitaliy! See my answer below... $\endgroup$
    – M.R.
    Commented Jul 5, 2012 at 3:30
  • $\begingroup$ @J.M.Absolutely, I just like Tanh ;-) $\endgroup$ Commented Jul 5, 2012 at 3:39
  • $\begingroup$ @Mike Thanks, your solution is cool too! +1 $\endgroup$ Commented Jul 5, 2012 at 3:40
  • $\begingroup$ This is good, but very slow for large Length[imgs]. $\endgroup$ Commented Mar 17, 2018 at 17:50
4
$\begingroup$

Vitaliy has a great answer, however I wanted to try my hand at this to get something a bit smoother in action by using Dynamics...

images = ImageResize[#, 500] & /@ ExampleData /@ ExampleData["TestImage"][[1 ;; 7]];
i = 1;
Dynamic[
    Which[Or @@ Thread[i == Range[Length[images]]], Pause[2]; i += .01, 
      i < Length[images] - 1, i += .01, 
      True, i = 1]; fade = Mod[i, 1];
 ImageCompose[images[[IntegerPart[i]]], {images[[IntegerPart[i] + 1]], fade}]
]

This works, but can someone please tell me why I can't substitute IntegerQ[i] for Or @@ Thread[i == Range[Length[images]]]?

$\endgroup$
3
  • 1
    $\begingroup$ Re your question, i has head Real, not Integer. $\endgroup$
    – rm -rf
    Commented Jul 5, 2012 at 4:08
  • $\begingroup$ Yes, Head[1 + .01] is Real; try: i == Round[i] $\endgroup$
    – Mr.Wizard
    Commented Jul 5, 2012 at 6:42
  • $\begingroup$ Oh right, thanks! $\endgroup$
    – M.R.
    Commented Jul 5, 2012 at 12:55

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.