Can someone tell me how to find the summation of all the pixel values in an image?

1 回表示 (過去 30 日間)
I'm trying to implement a Sum Average Difference (SAD) based code to find the difference between consecutive frames in a video to eliminate those frames which do not contain activity i.e. no motion.
  2 件のコメント
Sneheet
Sneheet 2014 年 1 月 26 日
yes, the absolute values of pixel differences.

サインインしてコメントする。

採用された回答

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 1 月 22 日
編集済み: Bruno Pop-Stefanov 2014 年 1 月 22 日
Assuming the frames you want to compare are called img_prev and img_next, both matrices of the same size, the following function computes what you want:
function out = sad(img_prev, img_next)
% First, take the absolute value of the difference at each pixel
myAbsDiff = abs(img_prev - img_next);
% Then, sum over all pixels
out = sum(myAbsDiff(:));
end
Using (:) you can transform matrix myAbsDiff into a vector. Calling sum on a vector computes the sum of all elements in a vector.
  3 件のコメント
Image Analyst
Image Analyst 2014 年 1 月 26 日
編集済み: Image Analyst 2014 年 1 月 26 日
No, as you can see he just defined it right there above. However, with uint8 images, it will need to be modified to allow negative numbers by casting the numbers to double.
function out = sad(img_prev, img_next)
% First, take the absolute value of the difference at each pixel
myAbsDiff = abs(double(img_prev) - double(img_next));
% Then, sum over all pixels
out = sum(myAbsDiff(:));
end
Walter Roberson
Walter Roberson 2014 年 1 月 26 日
No, Bruno has given you the code for it.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by