Hi i am trying to convert a blur function I implemented in C++ to MATLAB code, I am getting an error when trying to compute the sum of all elements in an array
Index exceeds the number of array elements (1).
Below is the C++ code.
Mat BlurFunc(Mat Grey, int winsize){ Mat Blur = Mat::zeros(Grey.size(), CV_8UC1); for (int i = winsize; i < Grey.rows - winsize; i++) { for (int j = winsize; j < Grey.cols - winsize; j++) { int sum = 0; for (int ii = -winsize; ii <= winsize; ii++) { for (int jj = -winsize; jj <= winsize; jj++) { sum += Grey.at<uchar>(i + ii, j + jj); } } Blur.at<uchar>(i, j) = sum / ((winsize * 2 + 1) * (winsize * 2 + 1)); } } return Blur;}
and this is what I am trying to get to work.
grey_img = rgb2gray(img);y = size(grey_img);for i=3:(rows-3) for j=3:(cols-3) A = grey_img(i-2:i,j-2:j); sum = sum(A(:)); y(i,j) = sum/49; endendimshow(uint8(y));
Best Answer