引言
核kernel矩阵定义为:[1 , 0, 0 ; 0, 0, 0; 0, 0, -1]. 那么,Y(i,j) = X(i,j) – X(i-1,j-1) + 128。当然,X,Y的取值均在0~255之间。
exit(EXIT_FAILURE);
}
nWidth = pImg->width;
nHeight = pImg->height;
pImgdata =(uchar*) pImg->imageData;
pImgChannels = pImg->nChannels;
step = pImg->widthStep;
int temp0,temp1,temp2;
for(int i =0; i<nWidth-1; i++){
for( int j =0; j<nHeight-1;j++){
if(pImgChannels ==1){ // gray image
if(flags ==IMAGECAMEO_0){ //sculputre processing
temp0 = pImgdata[(j+1)*step+(i+1)*pImgChannels]-
pImgdata[j*step+i*pImgChannels]+128;
}
if(flags ==IMAGECAMEO_1){ //engrave processing
temp0 = pImgdata[j*step+i*pImgChannels]-
pImgdata[(j+1)*step+(i+1)*pImgChannels] +128;
}
if(temp0>255) pImgdata[j*step+i*pImgChannels] = 255;
if(temp0<0) pImgdata[j*step+i*pImgChannels] = 0;
else pImgdata[j*step+i*pImgChannels] = temp0;
}
if(pImgChannels ==3){ // color image
if(flags == IMAGECAMEO_0){ //sculputre processing
temp0 = pImgdata[(j+1)*step+(i+1)*pImgChannels]-
pImgdata[j*step+i*pImgChannels] +128;
temp1 = pImgdata[(j+1)*step+(i+1)*pImgChannels+1]-
pImgdata[j*step+i*pImgChannels+1] +128;
temp2 = pImgdata[(j+1)*step+(i+1)*pImgChannels+2]-
pImgdata[j*step+i*pImgChannels+2] +128;
}
if(flags == IMAGECAMEO_1){ //engrave processing
temp0 = pImgdata[j*step+i*pImgChannels]-
pImgdata[(j+1)*step+(i+1)*pImgChannels]+128;
temp1 = pImgdata[j*step+i*pImgChannels+1]-
pImgdata[(j+1)*step+(i+1)*pImgChannels+1]+128;
temp2 = pImgdata[j*step+i*pImgChannels+2]-
pImgdata[(j+1)*step+(i+1)*pImgChannels+2]+128;
}
if(temp0>255) pImgdata[j*step+i*pImgChannels] = 255;
if(temp0<0) pImgdata[j*step+i*pImgChannels] = 0;
else pImgdata[j*step+i*pImgChannels] = temp0;
if(temp1>255) pImgdata[j*step+i*pImgChannels+1] = 255;
if(temp1<0) pImgdata[j*step+i*pImgChannels+1] = 0;
else pImgdata[j*step+i*pImgChannels+1] = temp1;
if(temp2>255) pImgdata[j*step+i*pImgChannels+2] = 255;
if(temp2<0) pImgdata[j*step+i*pImgChannels+2] = 0;
else pImgdata[j*step+i*pImgChannels+2] = temp2;
}
}
}
return pImg;
}
测试输出图像效果:
测试输出图像效果:
int flags)
{
if(!pMat.data){
std::cout<<“Error: Load FILE”<<std::endl;
exit(EXIT_SUCCESS);
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!