Reputation: 57
I want to do a Principal Component Analysis for a large number of samples. I have no problem subtracting the mean from audio samples, since audio only has 2 dimensions and I can easily use a for
loop .
However, this is a different case for video since each video sample has about 18-20 dimensions.
Example of content of one video file:
whos -file sample_video_001.mat
result: size: 54x96x19. bytes: 98496 . class: uint8. attributes: -
How can I compute this?
Upvotes: 0
Views: 397
Reputation: 18177
You can use the mighty bsxfun
to calculate the mean per dimension and directly subtract it from the original array.
A = randi(256,54,96,19,'uint8'); %// Some random data, replace with your own
B = double(A); %// Cast data to double
Bav = bsxfun(@minus,B,mean(B,3)); %// Subtract the mean
It turned out to be a bit more complicated that I initially thought, as you have a 'uint8'
class matrix. The mean of your data along the third dimension will not be an integer most likely, and will therefore be automatically set to class 'double'
, failing a direct bsxfun
. If you first convert your original data to 'double'
and then use bsxfun
it will work. Possibly you might have to divide by 256 to get data in the range [0 1]
to allow MATLAB to recognise it as a plottable format (so do B = double(A)./256;
). You cannot go back to 'uint8'
, since you subtract a non-integer mean from your data, so the result will not be integer either.
There's a function called pca
as well though, which is probably more suited to what you need, as it is a build-in function. Be sure that you know how to use it properly.
Upvotes: 4