Search code examples
matlabimage-processingaveragevideo-processing

Average between images results in a darker image


I'm trying to create the slow-motion of a 5 second video. In order to maintain the same frame-rate I need more frames. I extracted all the frames from the video and doubled them in number by creating new ones. Every frame has been combined with its successor to create an average frame to insert between them.

average = (predecessor + successor)/2

The result is spatially correct but it isn't in terms of colour. The average image is significantly darker than the originals. I'm trying to slow down a video of Federer playing tennis. The average image finds a middle ground between the original image and its successor. This effect can be seen between frames where the players and ball move significantly. The images below show the difference in colour that I'm trying to eliminate (Left: average, Right: Original)

enter image description herePredecessor (Original)

Why does this happen? Is there any better way to achieve what I'm trying to do?.


Solution

  • When working with integer arrays, MATLAB uses saturation arithmetic. This means that uint8(200) + uint8(200) == uint8(255).

    Assuming your images are uint8, adding up two white pixels leads to saturation, maximally bright white, which you then divide by two to get medium gray.

    To avoid this convert the images to a floating-point type, MATLAB defaults to double:

    average = uint8((double(predecessor) + double(successor))/2);
    

    But you can also use single if you’re worried about memory usage, as suggested by Ander in a comment..