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

조회 수: 2 (최근 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