cv::Vec3b determinePixelValueByConv(cv::Mat& neigbourhood){ int coeffs[3][3] = { { -1, -1, -1 }, { -1, 8, -1 }, { -1, -1, -1 } }; cv::Mat_ _neigbourhood = neigbourhood; cv::Vec3b centralPixel = _neigbourhood(1, 1); cv::Vec3b outputPixel = cv::Vec3b(); for (int k = 0; k < 3; k++){ int product_sum = 0; for (int i = 0; i < _neigbourhood.rows; ++i){ for (int j = 0; j < _neigbourhood.cols; ++j){ product_sum += (_neigbourhood(i, j)[k] * coeffs[i][j]); } } outputPixel[k] = cutToRange((int)(product_sum)); } return outputPixel; } cv::Mat edgingConvolution(cv::Mat& I){ cv::Mat imageCopy = shallowCopy(I); cv::Mat_ _I = I; for (int i = 1; i < I.rows - 1; i++){ for (int j = 1; j < I.cols - 1; j++){ cv::Mat neigbourhood = imageCopy(cv::Rect(j - 1, i - 1, 3, 3)); cv::Vec3b outputPixel = determinePixelValueByConv(neigbourhood); _I(i, j)[0] = outputPixel[0]; _I(i, j)[1] = outputPixel[1]; _I(i, j)[2] = outputPixel[2]; } } I = _I; return I; }