目录
计算
边缘
(资料图片仅供参考)
水平边缘
竖直边缘
计算
Mat src = (Mat_(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);//X方向—Robert算子Mat imgx;Mat kernel_x = (Mat_(2, 2) << 1, 0, 0, -1);filter2D(src, imgx, -1, kernel_x, Point(-1, -1), 0, 0);Mat imgy;//Y方向—Robert算子Mat kernel_y = (Mat_(2, 2) << 0, 1, -1, 0);filter2D(src, imgy, -1, kernel_y, Point(-1, -1), 0, 0);
src kernel_x kernel_y
imgx img_y
image_x值计算: image_y值计算:
image_x(0, 0) = 1 * 0 + 0 * 0 + 0 * 0 + (-1) * 1 = -1 image_y(0, 0) = 0 * 0 + 1 * 0 + (-1) * 0 + 0 * 1 =0
image_x(0, 1) = 1 * 0 + 0 * 0 + 0 * 1 + (-1) * 2 = -2 image_y(0, 1) = 0 * 0 + 1 * 0 + (-1) * 1 + 0 * 2 = -1
... ...
image_x(1, 1) = 1 * 1 + 0 * 2 + 0 * 4 + (-1) * 5 = -4 image_y(1, 1) = 0 * 1 + 1 * 2 + (-1) * 4 + 0 * 5 = -2
... ...
image_x(2, 2) = 1 * 5 + 0 * 6 + 0 * 8 + (-1) * 9 = -4 image_y(2, 2) = 0 * 5 + 1 * 6 + (-1) * 8 + 0 * 9 = -2
边缘
Mat src = (Mat_(5, 5) << 1, 2, 3, 4, 5, 2, 3, 6, 5, 7, 25, 35, 45, 35, 55, 7, 8, 9, 10, 11, 7, 3, 6, 8, 11);//X方向—Robert算子Mat imgx;Mat kernel_x = (Mat_(2, 2) << 1, 0, 0, -1);filter2D(src, imgx, -1, kernel_x, Point(-1, -1), 0, 0);Mat imgy;//Y方向—Robert算子Mat kernel_y = (Mat_(2, 2) << 0, 1, -1, 0);filter2D(src, imgy, -1, kernel_y, Point(-1, -1), 0, 0);
水平边缘
src
imgx imgy
竖直边缘
Mat src = (Mat_(5, 5) << 1, 2, 3, 4, 5, 2, 3, 6, 5, 7, 25, 35, 45, 35, 55, 7, 8, 9, 10, 11, 7, 3, 6, 8, 11);Mat tsrc = src.t();//X方向—Robert算子Mat imgx;Mat kernel_x = (Mat_(2, 2) << 1, 0, 0, -1);filter2D(tsrc, imgx, -1, kernel_x, Point(-1, -1), 0, 0);Mat imgy;//Y方向—Robert算子Mat kernel_y = (Mat_(2, 2) << 0, 1, -1, 0);filter2D(tsrc, imgy, -1, kernel_y, Point(-1, -1), 0, 0);
tsrc