I'm editing my post by giving all the code I have until now. I'd like to write a program which "unravels" randomly and piece by piece a given image. At the moment, I'm using an image randomly created with Image[] (endImage), and I'm starting with a grey background (whitePart and beginImage). I divide the image in partNumber x partNumber parts (here 10):

partNumber = 10;
allParts = Flatten[Outer[List, Range[1, partNumber], Range[1, partNumber]], 1];
endImage = ImagePartition[
   Image@RandomReal[1, {400, 400}]
whitePart = Image@Table[0.5, {400/partNumber}, {400/partNumber}];
beginImage = Table[whitePart, {partNumber}, {partNumber}];

(* After that, I create a random ordering of the unraveling of the parts with *)

replaceOrdering = RandomSample[allParts];

(* Then, a short function which replaces beginImage part number indexNumber with endImage part indexNumber: *)

replacePartWithNumber[tableOfParts_, indexNumber_] :=
  replaceOrdering[[indexNumber]] -> 
   endImage[[Apply[Sequence, replaceOrdering[[indexNumber]]]]]]

(* Creation of the list with recursion: *)

stage[1] = replacePartWithNumber[ beginImage, 1];
stage[n_] := replacePartWithNumber[stage[n - 1], n]

(* which finally gives the Animate command: *)

 {n, 1, Length@replaceOrdering, 1}
 , DefaultDuration -> 10
 , AnimationRepetitions -> 1]

This works for values of partNumber till ca. 25. But with partNumber = 40 or =50, Mathematica crashes immediately...

Any idea why this is? Any help greatly appreciated!

  • $\begingroup$ There is no way anyone can help you without knowing hoq sequence is defined. $\endgroup$
    – m_goldberg
    Nov 19 '13 at 8:56
  • $\begingroup$ How can we judge if you provide no information on your sequence? Your error message does not seem to be memory-related, are the frames generated by a function or is sequence an array of images? $\endgroup$
    – Yves Klett
    Nov 19 '13 at 8:56
  • $\begingroup$ My bad: I'm editing my post right now! $\endgroup$
    – Gabriel
    Nov 19 '13 at 9:32
  • $\begingroup$ You start your animation with n = 0. Perhaps that's what's wrong... $\endgroup$
    – cormullion
    Nov 19 '13 at 9:58
  • $\begingroup$ @cormullion: even when changing the start of the animation to n=1, Mathematica still crashes... $\endgroup$
    – Gabriel
    Nov 19 '13 at 10:01

With large values for partNumber, I get the message

$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>

The fix would be to increase $RecursionLimit.

Animate[Block[{$RecursionLimit = 10000}, ImageAssemble@stage[n]],
 {n, 1, Length@replaceOrdering, 1}, DefaultDuration -> 10, 
 AnimationRepetitions -> 1]

There would be no need for this fix, if the recursion were eliminated, like this:

stage[n_] := 
  Thread[Take[replaceOrdering, n] -> Extract[endImage, Take[replaceOrdering, n]]]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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