Incorrectly getting a blank video when using videowriter function to display data
18 views (last 30 days)
Show older comments
Diego on 28 Sep 2022
Commented: Walter Roberson on 3 Oct 2022
Hello, I am having a difficulty with writing and displaying a video for data that is meant to represent multiple frames that have been corrected for motion. I am essentially stabilizing the motion of a "shaky" video. I am still learning how to use Matlab within my research so this could be lack of coding experience on my end.
I am not receiving any error message but rather getting a video output of a blank video. In the first section, I am correcting the frame offsets. "Stabilized" should be the data used that I want to represent in a movie. When calling on it as a singular and averaged frames figure, I receive what I expect. The "Stabilized" file contains Y axis, X axis, RGB, and number of frames. The second section is my attempt to write a movie of my data which is where I believe I might be doing it incorrectly. I followed the examples provided in youtube and under "Help: Videowriter" in the command row, but nothing has worked. If more information is needed, please do not hesistate to ask. I greatly appreciate the help.
Walter Roberson on 28 Sep 2022
You are not changing the display between getframe() so all of the frames would be the same.
If you have pre-computed frames stored in stabilized then write them directly, like
for i = 1 : size(stabilized,3)
currFrame = stabilized(:,:,:,i);
And... you should be sure to initialize stabilized to the appropriate data type, such as
stabilized = zeros([2 2 1 1].*size(video), 'like', video);
which I suspect was the major source of your problem with the output being white.
Walter Roberson on 3 Oct 2022
With regards to the 'like' option, see https://www.mathworks.com/help/matlab/matlab_oop/class-support-for-array-creation-functions.html for more details on how like is implemented for classes.
More Answers (1)
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!