Ask Your Question
1

How to use InRange at Different Color Space and Range.

asked 2013-05-22 10:21:54 -0500

wuling gravatar image

updated 2015-10-30 16:11:07 -0500

Hi all, how to use InRange at different color space and Range. for example:in RGB space, 0<=R,G,B<=255, so,it's very easy to use:

inRange(const MatND& src, const Scalar& lowerb, const Scalar& upperb, MatND& dst)

But if i want the range out of the lowerb & upperb, for example: I want R color Range: 0<=R<=20, 100<=R<=255. like Aforge Color Filtering as picture. Also, in the other color space how to use InRange where the parameters out of the range. Thanks:)

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-05-22 10:39:47 -0500

berak gravatar image

updated 2013-05-22 10:43:16 -0500

inRange() can't do that, but not all hope's lost:

split your image into channels:

Mat orig; // bgr, probably
Mat chan[3];
split(orig,chan);  // chan[0]==blue, chan[1]==green, ..

apply your own operator on the channels to binarize them:

Mat bin_red = (chan[2]<20)|(chan[2]>100);  // note: single '|'
Mat bin_grn = (chan[1]<72)|(chan[1]>155);
Mat bin_blu = (chan[0]<64)|(chan[1]>155);

Mat bin = bin_red & bin_grn & bin_blu;  // where all conditions were met
edit flag offensive delete link more

Comments

It's very good idea,Thanks.

wuling gravatar imagewuling ( 2013-05-22 10:50:30 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-05-22 10:21:54 -0500

Seen: 10,022 times

Last updated: May 22 '13