MATLAB Answers

color segmentati​on/substra​ction of green screen from image

33 views (last 30 days)
Sharif on 31 Jul 2012
Commented: Image Analyst on 20 Apr 2015
Hi i have taken photos of rocks using a green screen as a background. please see:- <>>
i would like subtract the green bg as effectively as possible so that the boundary of the rock is preserved. would color segmentation be a good method? if so how can i achieve it? or perhaps a different seg method? thank sharif


Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 31 Jul 2012
Edited: Image Analyst on 31 Jul 2012
Get the separate color channels:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then look where the blue and red channels are dark and the green channel is high.
mask = (redChannel < 50) & (blueChannel < 50) & (greenChannel > 50);
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask,class(rgbImage)));
You copyrighted the image to prevent download, so that's about all I can do.


Sharif on 1 Aug 2012
first, thanks for getting back so quickly. sorry about copyright, flickr's default settings, fixed it now.
i tried it out but the uneven lighting is causing bad segmentation. i tried l.a.b color seg to avoid the lighting issue.('Color-Based Segmentation Using K-Means Clustering' you mentioned in a previous post) the results were much better. thanks again, sharif
KSY on 20 Apr 2015
Hi. I want to mask purple color what is the setting for red,green and blue channel?
Image Analyst
Image Analyst on 20 Apr 2015
Red and blue will be high and green will be low. Use impixelinfo() to let you mouse around the image and see what the RGB values are.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!