Why specifically do we need to cast frames to double to detect movement?

조회 수: 2 (최근 30일)
Andrew Killian
Andrew Killian 2021년 9월 6일
답변: Walter Roberson 2021년 9월 6일
In order to detect movement from subsequent frames... My understanding is that we subtract all the pixel values from the previous or next frame and if the differences are anything other than zero then movement has taken place. But our slide says :
– diff1 = abs(frame61 – frame62).
– diff2 = abs(frame63 – frame62).
• Note: frames must first be cast to double, Otherwise, the above lines will not work.
• E.g.: frame61 = double(frame61);
I was just wondering why specifically we need to do this. It offered no explanation.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 9월 6일
img = imread('cameraman.tif');
img2 = 2*fliplr(img);
imshowpair(img, img2)
Lots of differences, so you would expect that "movement" would be deteted on both the right and the left, right?
diff1 = img - img2;
imshow(diff1, [])
That's odd, almost no "movement" detected to the left ??
diff2 = double(img) - double(img2);
imshow(diff2, [])
But there it is if we used double() ... why didn't the first one work?
Well, look at this:
A = uint8(10)
A = uint8 10
B = uint8(20)
B = uint8 20
A - B
ans = uint8 0
double(A) - double(A)
ans = 0
Subtracting a uint8 from a uint8 always has to give a uint8 result. But uint8 cannot represent negative numbers.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by