How to deal with multi-channels Array

asked 2017-09-20 21:10:19 -0600

big-john gravatar image

I have two arrays:

   A (rows:60, cols:62,dim:2,channel:32)  and  F(rows:9, cols:9,dim:2,channel:32).

I want to compute Convolution with A and F, but it failed because the channel of A is more than 3. So the official API filter2d() not support this input Array!!! Now, I implement this function with for-loop :

  1. Split A into vector vecA,and the vecA.size=A.channel = 32 , the same as F and vecF.
  2. for-loop for computing Convolution

    cv::Mat acc;

    for( int i=0 ; i < vecA.size() ; i++) {

    cv::Mat dst;

    filter2d( vecA[i], dst , vecA[i].depth(), vecF[i], Point(-1, -1), 0, BORDER_CONSTANT);

    cv::add(acc, dst ,acc);

}

It is very ugly and not Efficient , so anyone have some ideas help me???

edit retag flag offensive close merge delete

Comments

with neural networks, this is often solved by flattening your channels, and stacking them into a huge matrix. (im2col/col2im)

then transform to dft space, where the convolution resolves to a per-element multiplication

berak gravatar imageberak ( 2017-09-21 04:05:48 -0600 )edit