问题描述
- 数组锐化运行结果图像失常
- 结果图片
相关代码:
for (int i = 1; i < m1-1; i++) {uchar *p_now = img_t3.ptr<uchar>(i); uchar *p_pre = img_t3.ptr<uchar>(i-1); uchar *p_nex = img_t3.ptr<uchar>(i+1); uchar *p_out = result.ptr<uchar>(i); for (int j = 0; j < m3; j++) { if (j == 0 || j == m3-1) { p_out[j*m2 + 0] = 0; p_out[j*m2 + 1] = 0; p_out[j*m2 + 2] = 0; } else { p_out[j*m2 + 0] = p_now[j*m2 + 0] * 5 - p_nex[j*m2 + 0] - p_pre[j*m2 + 0] - p_now[(j - 1) * m2 + 0] - p_now[(j + 1) * m2 + 0]; p_out[j*m2 + 1] = p_now[j*m2 + 1] * 5 - p_nex[j*m2 + 1] - p_pre[j*m2 + 1] - p_now[(j - 1) * m2 + 1] - p_now[(j + 1) * m2 + 1]; p_out[j*m2 + 2] = p_now[j*m2 + 2] * 5 - p_nex[j*m2 + 2] - p_pre[j*m2 + 2] - p_now[(j - 1) * m2 + 2] - p_now[(j + 1) * m2 + 2]; } }}uchar *r = result.ptr<uchar>(0);uchar *rr = result.ptr<uchar>(result.rows-1);for (int i = 0; i < m3; i++) { //对第一行和最后一行没有处理的像素设置黑色 r[i*m2 + 0] = 0; r[i*m2 + 1] = 0; r[i*m2 + 2] = 0; rr[i*m2 + 0] = 0; rr[i*m2 + 1] = 0; rr[i*m2 + 2] = 0;}
时间: 2025-01-21 00:32:51