2014-09-02 107 views
0

我使用一些图像,使影片在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'); 

现在,我必须找到所有的像素,其中第一和下一帧之间的差异较小你是否知道如何去做?

回答

2

我的猜测是在你的循环中添加如下内容。基本上创建尺寸的虚设矩阵(高度,宽度,9)(即图像的#-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的调用,但是当然可以通过将循环前面的帧存储在单元数组中来简化,然后简单地索引到数组中以计算差异。如果不清楚,请询问。

希望有帮助!

+0

谢谢你的回答!不幸的是,我得到这个错误,我不知道为什么:未定义的函数或方法'减'输入参数的类型'细胞'。 (大小(图像列表{1},1),大小(图像列表{1},2),长度(图像列表-1)); % 初始化矩阵 – user3748496 2014-09-02 17:27:32

+0

oups我把支架放在错误的地方!我将在我的答案中进行编辑。 – 2014-09-02 17:31:16

+0

我真的很抱歉浪费你的时间,但我仍然有错误,这次不同:下标赋值尺寸不匹配。 错误在==>无标题12在30 DiffMatrix(:,:,iImage)= DummyDiffFrames; – user3748496 2014-09-02 17:35:30

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也可能对你有用。

+0

谢谢你的回答。我并不需要对像素进行任何操作,我只需要找到它们(差异25):) – user3748496 2014-09-02 18:19:53

+0

不错的@horchler我不知道有关imabsdiff的知识! – 2014-09-02 18:22:33