# Calculate sum of absolute difference per pixel

I am trying to implement a research paper just to verify my results. I have shared the code (written by me) and the description of the process given in the research paper. Unfortunately my results are a bit different from his results that means I am doing something wrong. Kindly guide me in the right direction.

Here is the link to the paper: A parametric model for perceptual video quality estimation.

I have tried for mobile video sequence which can be downloaded from the following link: Yuv video sequences.

He gets 3.600 as SAD/pixel value while I am getting around 1.

Code:

fileName = 'mobile_cif.yuv';
width=352;
height=288;
numFrames=30;

%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
if t < numFrames %(Need to traverse to n-1 frames)
currFrame = result.cdata;    %reading Current frame
nextFrame = result.cdata;    %reading Next frame
% First, take the absolute value of the difference at each pixel
myAbsDiff = abs(double(currFrame) - double(nextFrame));
% Then, sum over all pixels
out = sum(myAbsDiff(:));
out=out/(width*height); %(Taking Average with respect to pixel)
out=out/64;%(Dividing By Block size to normalize)
disp(out);
else
continue;
end

end
disp(SAD/numFrames);  %(Taking Average with respect to Frames)


Process Description

Sum of absolute difference (SAD) is a simple video quality metric used for block comparison and for moving vectors calculations. Each frame is divided into small blocks (i.e. $8 \times 8$ pixels) and for every block in one frame the most similar (minimum SAD) block in next frame is find. This minimum sum of absolutes differences is assigned as the SAD for each block in each frame (up to the $n − 1$ frame). Then all the SAD values are averaged for each frame and for all the frames in the clip, and divided by the block area, for normalization.

• It'd be useful if you included a link to the paper, as well as an example of what you expected to get, and what you actually got. – MBaz Jun 4 '16 at 16:06
• @MBaz I have added the links. – Safi Mustafa Jun 4 '16 at 16:51
• Unfortunately my results are a bit different from his results that means I am doing something wrong not necessarily. Sometimes papers are wrong, sometimes you both can be right. But usually, yes, especially when I'm relatively new to a topic, I'd assume that I'm the one who did the mistake. – Marcus Müller Jun 4 '16 at 17:13
• @MarcusMüller Yes I am a beginner in this field. I don't know how to achieve this "Each frame is divided into small blocks (i.e. 8 × 8 pixels) and for every block in one frame the most similar (minimum SAD) block in next frame is find. This minimum sum of absolutes differences is assigned as the SAD for each block in each frame (up to the n − 1 frame)." – Safi Mustafa Jun 4 '16 at 17:33