フィルターのクリア

How to convert video to images (0~255) using background subtraction.

1 回表示 (過去 30 日間)
Kong
Kong 2020 年 3 月 11 日
コメント済み: Ameer Hamza 2020 年 3 月 11 日
Hello.
I wanna convert video to images (0~255).
When I used this code, I just got 0 or 1 (logical).
Can I get 0~255 instead of 0 or 1 (logical)? Thank you!
clear all
close all
%// read the video:
reader = VideoReader('lena_side.avi');
vid = {};
while hasFrame(reader)
vid{end+1} = im2single(readFrame(reader));
end
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4 );
%// estimate foreground as deviation from estimated background:
for i=1:60
fIdx(i) = i; %// do it for frame 1 ~ 60
fg{i} = sum( abs( vid{fIdx(i)} - bg ), 3 ) > 0.25;
fg{i} = reshape(fg{i},[],1);
end
D1 = cell2mat(fg);

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 11 日
  4 件のコメント
Kong
Kong 2020 年 3 月 11 日
Thank you so much!
Do you know the meaning (> 0.25;) ? what is the 0.25?
fg{i} = sum( abs( vid{fIdx(i)} - bg ), 3 ) > 0.25;
Ameer Hamza
Ameer Hamza 2020 年 3 月 11 日
I am not sure about it, but it seems like a threshold, below which the values are filtered. By inspecting the matrices, i found that the term sum( abs( vid{fIdx(i)} - bg ), 3 ) is uint8, so its value are in range [0-255]. Therefore comparison with 0.25 does not make much sense. I think 0.25 was meant when pixel intensity is scaled between [0-1]. So it seems that you should multiply it by 255, i.e., use > 0.25*255.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by