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

1 visualización (últimos 30 días)
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.

Respuestas (1)

Walter Roberson
Walter Roberson el 6 de Sept. de 2021
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.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by