2 lcc 633 lcc_633 于 2016.04.27 16:33 提问

数组锐化运行结果图像失常

结果图片
相关代码:
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;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!