本文介绍了从wiki实现白平衡算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从wiki中实现一些白平衡算法



它们只是一些简单的矩阵操作
do openCV提供任何函数做一些乘法
on像下面这样的像素组?



示例,2 x 2,3个通道Mat A =

  0 0 0 1 1 1 
2 2 2 3 3 3

3 x 3,1个频道Mat B =

  1 0 0 
0 2 0
0 0 3

A x B = C和C =


$ b b

  0 0 0 1 2 3 
2 4 6 3 6 9

我写了一些泛型函数来处理像素变换
,但我更喜欢openCV的build函数,因为openCV的
函数可以做一些优化

  template< typename T,typename UnaryFunctor> 
void transform_channel(cv :: Mat& src,int channel,UnaryFunctor functor)
{
int const channels = src.channels
if(channels == 1& src.isContinuous()){
return transform_continuous_channel< T>(src,functor);
}

for(int row = 0; row!= src.rows; ++ row)
{
auto dst_ptr = get_pointer&行,通道);
for(int col = 0; col!= src.cols; ++ col){
* dst_ptr = functor(* dst_ptr);
dst_ptr + = channels;
}
}
}


解决方案>

你会注意到,颜色平衡操作只包括对角矩阵,对应于一个元素乘以一个标量。因此,您的示例中的转换将是:

  image = image.mul(cv :: Scalar )); $ 3 

我不知道应用任意像素矩阵变换的函数。


I would like to implement some white balance algorithms from wikihttp://en.wikipedia.org/wiki/Color_balance

They are just some simple matrix manipulationDo openCV offer any functions to do some multiplicationon a group of pixels like following?

example, 2 x 2, 3 channels Mat A =

0 0 0 1 1 1
2 2 2 3 3 3

3 x 3, 1 channels Mat B =

1 0 0
0 2 0
0 0 3

A x B = C and C =

0 0 0 1 2 3
2 4 6 3 6 9

I have wrote some generic functions to deal with pixel transformationbut I would prefer the build in function of openCV if it exist since thefunctions of openCV may do some optimization

template<typename T, typename UnaryFunctor>
void transform_channel(cv::Mat &src, int channel, UnaryFunctor functor)
{
    int const channels = src.channels();
    if(channels == 1 && src.isContinuous()){
        return transform_continuous_channel<T>(src, functor);
    }

    for(int row = 0; row != src.rows; ++row)
    {
        auto dst_ptr = get_pointer<T>(src, row, channel);
        for(int col = 0; col != src.cols; ++col){
            *dst_ptr = functor(*dst_ptr);
            dst_ptr += channels;
        }
    }
}
解决方案

You will notice that color-balance operations consist only of diagonal matrices, which corresponds to an element-wise multiplication by a scalar. Thus, the transform in your example would be:

image = image.mul(cv::Scalar(1,2,3));

for a 3-channel image. I do not know of a function to apply arbitrary pixel-wise matrix transformations.

这篇关于从wiki实现白平衡算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:47
查看更多