How to do background subtraction between two images to find the ROI?

10 views (last 30 days)
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

Accepted Answer

Image Analyst
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
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!