How to make Mat as new whenever the function called again? [closed]

asked 2019-04-22 03:47:05 -0600

hua gravatar image

updated 2019-04-22 05:02:14 -0600

berak gravatar image

.

Mat rowPaddedImage;
//Row filter
int filter_size = 7;
int h = filter_size / 2;
int top, bottom, left, right;
top = bottom = left = right = h;

Scalar value(0, 0, 0);
copyMakeBorder(double_src, rowPaddedImage, 0, 0, left, right, BORDER_CONSTANT, value);
for (int i = 0; i < rowPaddedImage.rows; i++) //For img
    {
        for (int j = h; j < rowPaddedImage.cols - h; j++) //For img
        {
            for (int l = 0; l < f_size; l++) 
                {
                    colPaddedImage.at<Vec3d>(i + h, j - h)[0] += rowPaddedImage.at<Vec3d>(i, j - h + l)[0] * filter[l];                 
                    colPaddedImage.at<Vec3d>(i + h, j - h)[1] += rowPaddedImage.at<Vec3d>(i, j - h + l)[1] * filter[l];                 
                    colPaddedImage.at<Vec3d>(i + h, j - h)[2] += rowPaddedImage.at<Vec3d>(i, j - h + l)[2] * filter[l];
                }
        }
    }
//The row "rowPaddedImage"  is getting bigger and bigger after the row filter function is being called. If I called twice the padded row borders is 6 it is twice, if I call thrice it become three time the padded size.
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-17 17:25:03.883366

Comments

DON'T write code like that. Mat.at() should NEVER be used for a whole image.

can you instead try to tell us, what you're trying to achieve with it ? what's the goal / purpose here ? it for surecan bedone easier / safer.

berak gravatar imageberak ( 2019-04-22 05:15:47 -0600 )edit

I want to make the separable convolution (row filter and column filter) to a given image. And save the filtered image for the other processing.

hua gravatar imagehua ( 2019-04-22 09:22:55 -0600 )edit

I cannot use the filter2D function from OpenCV and have to write manually the convolution process. What is the optimal way to access image pixels? I'm a novice to OpenCV. Please guide me.

hua gravatar imagehua ( 2019-04-22 09:29:41 -0600 )edit

again, please try to use seperable filters ,NOT write loops

berak gravatar imageberak ( 2019-04-23 05:49:08 -0600 )edit

Can I use the like the following? filter1 is :

vector<double> filter1; //row vector

sepFilter2D(src, convolvedImg, CV_64FC3, filter1, filter1, Point(-1, -1), 0.0, BORDER_DEFAULT);


//filter1 = [0.00443305      0.0540056       0.242036        0.39905       0.242036        0.0540056       0.00443305]
hua gravatar imagehua ( 2019-04-23 21:08:47 -0600 )edit