Reputation: 6595
The color to grayscale algorithm is stated in the cvtColor() documentation. (search for RGB2GRAY).
Y = 0.299 R + 0.587 G + 0.114 B
I am using
cv::Mat i_test_base;
cv::cvtColor(white_balance_image, i_test_base, CV_RGB2GRAY);
cv::imshow("cvtColor", i_test_base);
cv::waitKey(0);
I'm working with Macbeth chart and it can result too low signal level when detecting e.g. blue patch. Using just sum between channels or max of the RGB values would most likely work better.
I tried something like
cv::transform(white_balance_image, i_test_base, cv::Matx13f(1, 1, 1));
cv::imshow("transform", i_test_base);
cv::waitKey(0);
but this doesn't work, I get a white image. do I need to scale or something like that?
Upvotes: 2
Views: 2290
Reputation: 16810
In your cv::transform
, make sure that the weights sum to 1 (or less) to avoid saturation.
If you use
cv::transform(white_balance_image, i_test_base, cv::Matx13f(0.114, 0.587, 0.299));
on a BGR image you should get the same as BGR2GRAY
. If you use (1/3.0, 1/3.0, 1/3.0)
instead, you should get an average of the 3 channels. Adjust to your liking.
Upvotes: 2