Ask Your Question
0

custom grayscale conversion

asked 2013-05-06 04:59:52 -0600

efanucar gravatar image

I'm trying to improve my edge detection and found out, what is logical: some edges are detected better in the red channel, others in the green etc. I would like to use only one Canny-call and not three on each channel. When I use BGR2GRAY the mixture of the channels is not optimal for my camera live image.

Is it possible to change the weight of each channel during the conversion? Or is there any known custom algorithm for this?

Thanks!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-05-06 08:04:15 -0600

As you can see here, image conversion is a product, therefore, you can do it yourself, with your own value: make a loop on pixels and convert BGR values to gray with your constants.

edit flag offensive delete link more
1

answered 2015-03-25 15:38:33 -0600

ClintFromVa gravatar image

For only a single channel, you could use this:

Mat src_grn = Mat::zeros(src.rows, src.cols, CV_8UC1); //green channel from src
int from_to[] = { 1, 0 }; //copy green channel only (assume BGR)
mixChannels(&src, 1, &src_grn, 1, from_to, 1);

I'm grabbing the green only from a white-hot object, which has the best contrast. Dimmer things will need some other tricks though...let me know how it goes!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-06 04:59:52 -0600

Seen: 2,031 times

Last updated: Mar 25 '15