1 opencv 坐标原点是左上角 x向右延伸 y向下延伸
图像的坐标原点位于左上角,x 轴向右延伸,y 轴向下延伸。这种坐标系与大多数计算机图像处理库(如 pil、matlab 等)一致
例如 给定像素坐标(x,y) 则周围点表示为:
左上方的像素: (x-1, y-1)
上方的像素: (x, y-1)
右上方的像素: (x+1, y-1)
左侧的像素: (x-1, y)
右侧的像素: (x+1, y)
左下方的像素: (x-1, y+1)
下方的像素: (x, y+1)
右下方的像素: (x+1, y+1)
2 对于卷积核操作 中间写8 那就是中间像素值*8 周围的写-1 周围像素*(-1) 最终加到一起计算出新的像素 赋给卷积后的点
例如 给定一个卷积核(通常称为滤波器),如下所示:
-1 -1 -1
-1 8 -1
-1 -1 -1
这个卷积核表示的操作是:将中心像素值乘以 8,然后减去它周围的每个像素值。具体步骤如下:
- 将中心像素的值乘以 8。
- 将周围八个像素的值分别乘以 -1。
- 将上述所有值相加,得到新的像素值。
合成后新公式就是:
o(x,y)=8*i(x,y)−i(x−1,y−1)−i(x−1,y)−i(x−1,y+1)−i(x,y−1)−i(x,y+1)−i(x+1,y−1)−i(x+1,y)−i(x+1,y+1)
3 对于边缘处理情况 可以用0填充 可以用边缘像素填充 可以用另一侧边缘像素填充 都是预定义宏
border_constant border_reflect border_replicate border_wrap
例如(cpp):
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
// 创建一个示例图像(3x3矩阵)
mat image = (mat_<uchar>(3, 3) << 1, 2, 3,
4, 5, 6,
7, 8, 9);
// 定义卷积核(边缘检测或锐化)
mat kernel = (mat_<float>(3, 3) << -1, -1, -1,
-1, 8, -1,
-1, -1, -1);
// 创建用于存储结果的图像
mat result;
// 使用不同的边缘填充方法进行卷积操作
// 1. 零填充(border_constant)
filter2d(image, result, -1, kernel, point(-1, -1), 0, border_constant);
cout << result << endl << endl;
// 2. 镜像填充(border_reflect)
filter2d(image, result, -1, kernel, point(-1, -1), 0, border_reflect);
cout << result << endl << endl;
// 3. 重复边缘像素填充(border_replicate)
filter2d(image, result, -1, kernel, point(-1, -1), 0, border_replicate);
cout << result << endl << endl;
// 4. 环绕填充(border_wrap)
filter2d(image, result, -1, kernel, point(-1, -1), 0, border_wrap);
cout << result << endl << endl;
return 0;
}
发表评论