How to convert video to images (0~255) using background subtraction.
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
Ameer Hamza
2020-3-11
imgUINT8 = im2uint8(img0_1);
4 个评论
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!