Brightness/Histogram normalization for time lapse images
<p>I'm working in a laboratory and we often make time lapse series (image every hour) of stem cells. The current idea is to put all frames together and make a video showing this growing cells (similar to this <a href="https://www.youtube.com/watch?v=zSuLDqRfhXo" rel="nofollow">youtube video</a>). Which could done simple and cool using OpenCV + Python.</p>

<pre class="lang-py prettyprint-override"><code>import numpy as np
import os
import cv2

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

timelapse_folder = '../myTimeLapse/'

for file in os.listdir(timelapse_folder):
    frame = cv2.imread(timelapse_folder+file, 0)
    out.write(frame)

out.release()
</code></pre>

<p>But we have the problem, that all images vary a little bit in brightness, so we get some flickering in our output video. </p>

<p>I'm not allowed to upload the videos but here are some simple examples generated with gimp to visualize the problem:</p>

<p>That's the video I get from the frames</p>

<p><a href="http://i.stack.imgur.com/ZLYUq.gif" rel="nofollow"><img src="http://i.stack.imgur.com/ZLYUq.gif" alt="enter image description here"></a></p>

<p>and that's my desired video (it would be also great to minimize the flickering instead of removing it completely)</p>

<p><a href="http://i.stack.imgur.com/Gtu7C.gif" rel="nofollow"><img src="http://i.stack.imgur.com/Gtu7C.gif" alt="enter image description here"></a></p>

<p>Is there a way to adjust the histogram or brightness over all images (or maybe between 2 images) to remove those flickering using OpenCV?</p>

<p>Thanks for every idea or hint! </p>

<p><em>Edit: The gif sequence produced by Andrew's idea (Answer below)</em></p>

<p><a href="http://i.stack.imgur.com/8oGio.gif" rel="nofollow"><img src="http://i.stack.imgur.com/8oGio.gif" alt="enter image description here"></a></p>

<p>Are those images RGB or gray values? I would just perform a normalization in your loop after reading each frame:</p>

<pre><code>frame = frame/np.max(frame)
</code></pre>

<p>In case of gray values each image should then have values between 0 and 1 but depending on how your images look like you could also try other normalizations, e.g. using the <code>np.median</code> or <code>np.mean</code> instead of <code>np.max</code>.</p>

python opencv timelapse