如何量化短视频中的像素变化

时间:2014-10-28 14:30:09

标签: matlab video pixels

在最近的一项研究中,我一直使用短片(20s)作为刺激材料。我现在想比较有关每个视频包含的移动量的视频。

这是我的代码,直到现在:

VidObj = VideoReader(video_file); 
VidFrames = read(VidObj); 

返回4D Matrix = 2d图像的2d数组= a x b x c x VidNoFrames

VidNoFrames = VidObj.NumberofFrames; 
VidHeight = VidObj.Height; 
VidWidth = VidObj.Width; 

    for k = 1 : VidNoFrames 
       k mov(k).cdata = VidFrames(:,:,:,k); %720 x 1280 x 3 
    end 

现在我想下一步将构建相关/ SSD的循环。但是,cdata仍然是3D(高x宽x 3)。我不明白这第三个维度是什么,以及如何继续比较图像...非常感谢你的帮助!

非常感谢! 恭

1 个答案:

答案 0 :(得分:2)

您可能希望使用相关性来比较2个图像,或者在您的情况下,我会选择计算总和方形强度差异,它会以更加定量的方式告诉您可能从一个图像到另一个图像的像素强度有多大差异。以下是两种情况的简单示例;

clear
clc

%// Correlation coefficient. Close to 1 == more similarity
A = imread('coins.png');

B = medfilt2(A);

CorrCoeff = corr2(A,B)

%// Sum Square Intensity Difference


SquareIntDiff = (B-A).^2; %//Compute the square of the pixel intensity difference.

SSID = sum(SquareIntDiff(:)) %// Sum it to get the SSID. A value of 0 means that both images are similar in terms of pixel intensity. 
%// Using sum(sum(SquareIntDiff)) would yield the same result in a less efficient manner. MATLAB  takes the sum along the columns and then another time to get a single value.


CorrCoeff =

    0.9964


SSID =

      550746

当然,您可以在循环中轻松实现此功能,以比较视频中的连续帧。希望对你有所帮助:))