圖像特效之浮雕與雕刻

<!-- lang: cpp -->
///////////////////////////////////////////////////////////

//Parameters:
// pImg: input image
// flags: IMAGECAMEO_0 : sign sculputre in image processing
// IMAGECAMEO_1 : sign engrave in image processing
///////////////////////////////////////////////////////////
IplImage *ImageEffect::ImageCameo(IplImage pImg, int flags)
{
if(!pImg){
printf("Errror: Load File in ImageCameo(.).\n");
exit(EXIT_FAILURE);
}
nWidth = pImg->width;
nHeight = pImg->height;
pImgdata =(uchar
) pImg->imageData;
pImgChannels = pImg->nChannels;code

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[jstep+ipImgChannels]-
pImgdata[(j+1)step+(i+1)pImgChannels] +128;
}
if(temp0>255) pImgdata[j
step+i
pImgChannels] = 255;
if(temp0<0) pImgdata[jstep+ipImgChannels] = 0;
else pImgdata[jstep+ipImgChannels] = 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[jstep+ipImgChannels]-
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;
}input

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;
}it

在此輸入圖片描述 在此輸入圖片描述

相關文章
相關標籤/搜索