How to do background subtraction between two images to find the ROI?
10 views (last 30 days)
Show older comments
Jawad Siddique
on 24 Nov 2017
Commented: Image Analyst
on 17 Apr 2020
I took two frames,I want to subtract the background so that I can work on the region which I am Interested(Human). I have attached two pictures.
is the image of a road.The image with a human is this
Please help me with the code.I want to separate the human and crop the human region.
Thank you
0 Comments
Accepted Answer
Image Analyst
on 24 Nov 2017
Just subtract
diffImage = double(rgbImage1) - double(rgbImage1);
and threshold above the noise level (say it's 10 gray levels.
mask = abs(diffImage) > 10;
To get a mask where any color channel is more than 10:
mask = any(mask, 3);
To get a mask where all color channels are more than 10:
mask = all(mask, 3);
Now mask is a 2-D logical array.
9 Comments
Image Analyst
on 17 Apr 2020
Do you mean like this (I'm just copying and pasting):
% Just subtract
diffImage = double(rgbImage1) - double(rgbImage1);
% and threshold above the noise level (say it's 10 gray levels.
mask = abs(diffImage) > 10;
% To get a mask where any color channel is more than 10:
mask = any(mask, 3);
% To get a mask where all color channels are more than 10:
mask = all(mask, 3);
% Now mask is a 2-D logical array.
Obvously you'll have to call imread() or whatever to read in your own rgbImage1 and rgbImage2.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!