我已经在R中使用.png生成了多个ggplot图,我需要制作一个这些情节的视频。为此,我正在尝试使用MATLAB。我能够生成视频,但质量很差,在视频中看不到任何颜色,尽管我的.png文件是彩色的。ggplot命令如下所示:
ggplot(vel1,aes(vel1[,1],vel1[,2],color=vel1[,14639])) +geom_point()+ scale_color_manual(breaks = c("8", "6", "4"), values=c("red", "blue", "green"))我使用的MATLAB代码是:
writerObj = VideoWriter('1889_2121.avi');
writerObj.FrameRate=15;
open(writerObj);
for K = 1889:2:2121
filename = sprintf('vel_cluster%d.png', K);
thisimage = imread(filename);
writeVideo(writerObj, thisimage);
end
close(writerObj);您可以在这里访问示例.png文件和视频,用于测试的示例文件。你能帮我解决这个问题吗。
发布于 2018-02-16 12:36:51
您不能打开相应的颜色图。
thisimage = imread(filename);返回像素的uint8值。
[thisimage,map] = imread(filename);给你的彩色地图使用。
frame.cdata=thisimage;frame.colormap=map;
writeVideo(writerObj, frame);应该能起作用。
但我同意评论者的观点,即gganimate应该比Matlab更适合你想做的事情。
https://stackoverflow.com/questions/48820987
复制相似问题