How to deal with multi-channels Array
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 :
- Split A into vector vecA,and the vecA.size=A.channel = 32 , the same as F and vecF.
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???
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