Ask Your Question
2

Replace a range of colors with a specific color

asked 2013-05-26 02:59:05 -0600

heredic gravatar image

Is there a function that receives an image/frame Mat M, a range R of RGB/A colors, and an RGB/A color C, and replaces occurrences (pixel values) of R with C?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-05-26 06:52:10 -0600

rics gravatar image

updated 2013-05-27 08:38:36 -0600

You can use inRange to determine if a certain pixel is in the range R. Then you can set the pixels of Mat M to C where the output of inRange is non-zero using setTo.

It is like (not tested/compiled):

inRange(M,RangeLow,RangeHigh,Mask);
M.setTo(C,Mask);

Another solution could the usage of LUT function. You need to define a lookup table (hence the name) which is a simple array on conversion values where you set all the pixels in the range R to C. Then you can call:

LUT(M,lookuptable,M);
edit flag offensive delete link more

Comments

@rics thanks! Is there any chance of example code..? Only if you feel like it :)

heredic gravatar imageheredic ( 2013-05-26 08:06:59 -0600 )edit

Is there a python based API for doing this?

helxsz gravatar imagehelxsz ( 2016-06-28 00:07:25 -0600 )edit

Question Tools

Stats

Asked: 2013-05-26 02:59:05 -0600

Seen: 12,653 times

Last updated: Jun 28 '16