Visualization of traces of moving objects - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-22T11:21:07Z https://mathematica.stackexchange.com/feeds/question/87795 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/87795 7 Visualization of traces of moving objects mrz https://mathematica.stackexchange.com/users/19892 2015-07-08T17:08:40Z 2016-12-20T12:28:52Z <p><strong>An example movie which is made with the listed mathematica code below shows traces of moving objects:</strong></p> <p><a href="https://youtu.be/8jN2uuSHCEg" rel="nofollow noreferrer">https://youtu.be/8jN2uuSHCEg</a> (Melting ...)</p> <p><a href="http://youtu.be/5ET62846C-I" rel="nofollow noreferrer">http://youtu.be/5ET62846C-I</a> (Crystallisation ...)</p> <p>The following question is related to:</p> <p><a href="https://mathematica.stackexchange.com/questions/69305/speed-up-calculation">Speed up calculation</a></p> <ol> <li>I have thousands of gray scale images.</li> <li>I want to superpose <code>image_1</code> to <code>image_50</code>, <code>image_2</code> to <code>image_51</code>, <code>image_3</code> to <code>image_52</code>, ..., <code>image_951</code> to <code>image_1000</code>, ... This is always a set of <code>50 images</code>.</li> <li>For the superposition each image is binarized and then colorized differently. The resulting images are <code>col_Image_1</code>, <code>col_Image_2</code>, ... <code>col_Image_50</code>. The color is varying from <code>col_Image_1</code> to <code>col_Image_50</code> following a certain color table (see below). </li> <li>Here is a set of 3 images to illustrate the superposition of circular shaped objects: <code>col_Image_1</code> has only black and blue pixels, <code>col_Image_2</code> has only black and green pixels and <code>col_Image_3</code> has only black and red pixels.</li> </ol> <p><img src="https://i.stack.imgur.com/GNwJR.png" alt="enter image description here"></p> <p>The superposed image shows red over green over blue:</p> <p><img src="https://i.stack.imgur.com/zARGF.png" alt="enter image description here"></p> <p>Here you can find a set of 200 gray scale images. <a href="http://bit.ly/1CpyIK1" rel="nofollow noreferrer">http://bit.ly/1CpyIK1</a> (12.5 MB)</p> <p>These images I have analyzed with the following code (which produces the expected resulting images (200 images yield 151 superposed images), but is still relatively slow). I have a 4 core i7 processor and have used ParallelTable. For calculating 151 images and writing them to files it takes around 110 sec.</p> <p>The (until now fastest) solution for the superposition is from <a href="https://mathematica.stackexchange.com/users/862/simon-woods">https://mathematica.stackexchange.com/users/862/simon-woods</a></p> <pre><code>bins = Table[ Clip[Import[fNames[[i]], "GrayLevels"], {0.18, 0.18}, {0, i/number}], {i, number}]; superImg = Colorize[Image[Map[Max, Transpose[bins, {3, 1, 2}], {2}]], ColorFunction -&gt; (Blend[colTable, #] &amp;)]; </code></pre> <p>My code is given here, which I would like to make faster is here:</p> <pre><code>ChoiceDialog[{FileNameSetter[Dynamic[imageDir], "Directory"], Dynamic[imageDir]}]; colTable = {{Black}, Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 1/255, 1, 1/255}]}; colTable = Flatten[colTable]; SetDirectory[imageDir]; fNames = FileNames["*.png"]; numFiles = Length[fNames]; number = 50; ParallelTable[ bins = Table[ Clip[Import[fNames[[i + j]], "GrayLevels"], {0.25, 0.25}, {0, i/number}], {i, 1, number}]; superImg = Colorize[Image[Map[Max, Transpose[bins, {3, 1, 2}], {2}]], ColorFunction -&gt; (Blend[colTable, #] &amp;)]; fileName = StringJoin[imageDir, "/out_", ToString[j + 1], ".png"]; Export[fileName, superImg, "PNG"]; , {j, 0, numFiles - number} ] </code></pre> <p>You can download all the superposed images here: <a href="http://bit.ly/1CoXsSr" rel="nofollow noreferrer">http://bit.ly/1CoXsSr</a> (15.7 MB)</p> <p>For example superposed image no. 66 (out of 151 images) is:</p> <p><img src="https://i.stack.imgur.com/MUjim.png" alt="enter image description here"></p> <p>A superposition using all 200 images (number = 200) yields:</p> <p><img src="https://i.stack.imgur.com/ZlS2M.png" alt="enter image description here"></p> <blockquote> <p>And now my question: Can my mathematica code be optimized/faster?</p> </blockquote>