C++ Blur function to MATLAB code
이전 댓글 표시
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;
end
end
imshow(uint8(y));
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Call C/C++ from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!