(MATLAB)用于视频/动画的色图 [英] (MATLAB) Colormap for video/animation

查看:96
本文介绍了(MATLAB)用于视频/动画的色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以生成一系列灰度图像.然后,我可以将图像单独保存为一个循环,并在应用了色图的情况下保存它们.即

I have some code that produces a series of grayscale images. I am then able to save the images individually in a loop and save them with a colormap applied. i.e.

file = sprintf('image_%04d.png',x);
imwrite(image1,jet,file,'png');

所以我将图像从另一端取出,它们具有正确的颜色映射,即colormap(jet).

So i get my images out the other end and they have the correct colormapping which is colormap(jet).

但是,当我在下一个程序中尝试将这些图像拼凑在一起以形成简短的动画时(是的,我知道我应该按照与上述相同的循环制作电影),但是我得到的是灰度电影!!!当源图像是彩色的时,怎么办?

However, when in my next program, I try to cobble these images together to form a short animation (yes I know I should just make the movie in the same loop as above), I get a grayscale movie!!! How does that happen when the source images are color?

我还注意到,如果我加载单个图像然后键入:

Further more I notice that if I load an individual image and then type:

imshow(A)

我也得到了灰度图像!但是如果我输入:

i get a grayscale image too! but if I type:

image(A)

它给了我我想要的东西,这就是色彩映射的图像.

it gives me what I wanted, which is the colormapped image.

为什么要这样做?如何获得具有正确色彩图的电影?并且有一种方法可以在保存颜色映射之前将其添加到图像中(如上所述,我在写入时添加颜色映射)?

Why does it do this? how can I get it to make a movie with the correct colormap? and is there a way I can add the colormap to the image before saving it (as above I add the map during imwrite)?

p.s.我尝试使用:

p.s. I have tried using :

video = videowriter(VideoFileName,'MPEG-4')
video.Colormap = jet  (or) colormap(jet) or 'jet'

matlab不喜欢那样.:(

matlab doesnt like that. :(

推荐答案

Alex,VideoWriter有一个名为"Indexed AVI"的配置文件,该配置文件使您可以将图像与色图信息一起保存.您可以使用以下代码:

Alex, VideoWriter has a profile called 'Indexed AVI' which will allow you to save the image with the colormap information. You can use the code below:

vwObj = VideoWriter('myfile.avi', 'Indexed AVI');
vwObj.Colormap = jet(256);
open(vwObj);
writeVideo(vwObj, image1);   % Repeat for all images that you want
close(vwObj);

MPEG-4文件不接受Colormap属性.但是,您可以在编写时通过提供如下所示的MATLAB框架来指定颜色图:

MPEG-4 files do not accept a Colormap property. However you can specify a colormap at the time of writing by supplying a MATLAB frame as bellow:

vwObj = VideoWriter('myfile', 'MPEG-4');
open(vwObj);
f.cdata = image1;
f.colormap = jet(256);
% The colormap will be applied before writing the data to the MPEG4 file
writeVideo(vwObj, f); 
close(vwObj);

希望这会有所帮助.

Dinesh

这篇关于(MATLAB)用于视频/动画的色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆