Background subtraction in an RGB Image

how can i do a background subtraction on an RGB image?
image1.jpg

댓글 수: 6

Adam
Adam 2018년 11월 13일
Depends entirely on the image. In general terms the steps are to identify the background, then subtract it!
Fodio Longman
Fodio Longman 2018년 11월 13일
I mean can i have a code for this please?
Adam
Adam 2018년 11월 13일
Code for what? Define a specific problem and someone might provide code, but this is far too vague. What counts as 'background'?
Image Analyst
Image Analyst 2018년 11월 13일
Again, what constitutes as background? The white surround? The black surround? Something else? If it's the white, are you sure you don't want to crop instead of subtract?
Fodio Longman
Fodio Longman 2018년 11월 13일
I want to take out the black sorround from the image. That is my aim
Thank you
Image Analyst
Image Analyst 2018년 11월 13일
You can't. At best you could crop it down to the object in the image, giving a rectangular image. Images must remain rectangular and not have some ragged irregular shape.

댓글을 달려면 로그인하십시오.

답변 (3개)

Fodio Longman
Fodio Longman 2018년 11월 13일

0 개 추천

I have attached the image i want to subtract the black background from the image.
Thank you

댓글 수: 1

Adam
Adam 2018년 11월 13일
And what do you want to replace it with? The colour of the axes behind?

댓글을 달려면 로그인하십시오.

Adam
Adam 2018년 11월 14일

0 개 추천

Well, you can do something like this:
rgb = rand( 5, 5, 3 ); % Random image
rgb( 2, 3, : ) = [0 0 0]; % Turn a pixel black
rgb( 4, 3, : ) = [0 0 0]; % Turn a pixel black
mask = sum( rgb, 3 ) > 0;
figure; h = imagesc( rgb );
h.AlphaData = mask;
Obviously in your case you don't need the first 3 lines, they are just for me to create an example of an image with some black pixels.
Bear in mind though that this will make all black pixels transparent so that you see the colour of the axes underneath, so if you have bona fide black pixels elsewhere within your image this will make them transparent too which is not desirable.
In that case you would have to run some kind of algorithm which would work out the boundary of your desired image to segment out the background, but that is not my area of expertise. The remaining part would be the same though - however you create the background mask, just set its inverse as the AlphaData (Note that my mask above is actually the non-mask because we are setting it as AlphaData where 1 means opaque and 0 means transparent).

제품

질문:

2018년 11월 13일

답변:

2018년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by