Matlab中的电影,帧之间的区别

时间:2014-09-02 16:34:38

标签: matlab

我必须使用一些图像在Matlab中制作电影,我做到了:

ImageList = {'AT3_1m4_01.tif', 'AT3_1m4_02.tif', 'AT3_1m4_03.tif', ... 
'AT3_1m4_04.tif', 'AT3_1m4_05.tif', 'AT3_1m4_06.tif', ... 
'AT3_1m4_07.tif', 'AT3_1m4_08.tif', 'AT3_1m4_09.tif','AT3_1m4_10.tif' }; 

 writerObj = VideoWriter('film22.avi'); 


fps = 1; 
writerObj.FrameRate = fps; 


open(writerObj); 


 for iImage = 1:10 
  Frame = imread(ImageList{iImage}); 

   writeVideo(writerObj,Frame); 
end 


close(writerObj); 
implay('film22.avi');

现在,我必须找到所有像素,其中第一帧和下一帧之间的差异小于25.您是否知道该怎么做?

2 个答案:

答案 0 :(得分:2)

我的猜测是在你的循环中添加如下内容。基本上创建一个维度矩阵(高度,宽度,9)(即图像数量为-1),并将值1分配给差值小于25的像素。

ImageForInfo = imread(ImageList{1}); % Get infos about images, i.e. width and height.

ImageHeight = size(ImageForInfo,1);
ImageWidth = size(ImageForInfo,2);

DiffMatrix = zeros(ImageHeight,ImageWidth,length(ImageList)-1); % Initialize matrix

DummyDiffFrames = zeros(size(ImageForInfo)); % Dummy matrix for finding pixel values that interest you.

for iImage = 1:10 

   Frame = imread(ImageList{iImage}); 
   writeVideo(writerObj,Frame); 


  if iImage < 10
     DummyDiffFrames(find(imread(ImageList{iImage}) - imread(ImageList{iImage+1}) < 25)) = 1; % Assign 1 where pixel difference is less than 25.

     DiffMatrix(:,:,iImage) = DummyDiffFrames;
  end

end 

由于在循环中调用imread,它看起来很复杂,但你当然可以通过在循环之前将帧存储在单元格数组中来简化,然后简单地索引到数组中以计算差异。如果不清楚,请询问。

希望有所帮助!

答案 1 :(得分:1)

使用Image Processing Toolbox,您可以利用imabsdiff,它基于用C编写的mex函数。示例:

Frame1 = imread(ImageList{1});
writeVideo(writerObj,Frame1);
for iImage = 2:10 
    Frame = imread(ImageList{iImage});

    Z_25 = imabsdiff(Frame1,Frame) > 25; % Difference with respect to first frame
    bwDiffImg = double(Z_25);            % Black & White difference image
    % Do something with your diff image or use idx=find(Z_25) to find indices...

    writeVideo(writerObj,Frame);
end

如果您需要在Z_25以上查找索引,请查看find的文档。或者您可以通过logical indexing直接使用Z_25。你的问题并没有具体说明你在这方面究竟想要什么,而你已经接受了答案,所以我不打算猜测。 imsubtract也可能对您有用。