im2frame grayscale images colormap error
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi
I'm trying to combine grayscale jpeg images into a movie file (.avi) using matlab. I keep getting the following colormap error message when using the following code:
Error using im2frame Indexed movie frame must have a non-empty colormap
Error in untitled2 (line 36) writeVideo(writerObj,im2frame(Frame,graymap));
%%Create video out of list of jpgs
clc;
close all;
clear all;
%%Folder with all the image files you want to create a movie from, choose this folder using:
ImagesFolder = uigetdir;
%%Verify that all the images are in the correct time order, this could be useful if you were using any kind of time lapse photography. We can do that by using dir to map our images and create a structure with information on each file.
jpegFiles = dir(strcat(ImagesFolder,'/*.jpg'));
%%Sort by date from the datenum information.
S = [jpegFiles(:).datenum];
[S,S] = sort(S);
jpegFilesS = jpegFiles(S);
% The sub-structures within jpegFilesS is now sorted in ascending time order.
% Notice that datenum is a serial date number, for example, if you would like to get the time difference in hours between two images you need to subtract their datenum values and multiply by 1440.
%%Create a VideoWriter object, in order to write video data to an .avi file using a jpeg compression.
VideoFile = strcat(ImagesFolder,'/MyVideo.avi');
writerObj = VideoWriter(VideoFile);
%%Define the video frames per second speed (fps)
fps = 1;
writerObj.FrameRate = fps;
%%Open file for writing video data
open(writerObj);
%%Running over all the files, converting them to movie frames using im2frame and writing the video data to file using writeVideo
for t = 1:length(jpegFilesS)
graymap = gray(256);
[Frame graymap] = imread(strcat(ImagesFolder,'/',jpegFilesS(t).name));
writeVideo(writerObj,im2frame(Frame,graymap));
end
%%Close the file after writing the video data
close(writerObj);
end
0 commentaires
Réponses (2)
Walter Roberson
le 14 Jan 2016
JPEG images are never indexed images, and are very seldom grayscale. When you imread() in that form you are replacing the graymap variable with the empty colormap (because colormap is output as empty for non-indexed images.) The empty colormap is then being rejected by im2frame()
Probably you should just not be using the colormap there at all.
0 commentaires
Image Analyst
le 14 Jan 2016
See my attached demo for splitting up a video into individual frames (disk files), and then recalling them and building them back into a movie.
0 commentaires
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!