0
我想模糊图像。只在某些部分不是全部图像模糊
我使用了一个名为k[][3]= { 1, .01, 1, .01, 0, .01, 1, .01, 1};
代码内核如下:
void blur(IplImage *notgray)
{
IplImage *img = cvCreateImage(cvGetSize(notgray), notgray->depth, 1);
cvCvtColor(notgray, img, CV_RGB2GRAY);
int rows=img->height,cols=img->width,row,col,i,j,ki,kj;
uchar* temp_ptr=0 ;
float sum,k[][3]= { 1, .01, 1,
.01, 0, .01,
1, .01, 1};
for(row = 0; row < rows; ++row)
{
sum=0;
for (col = 0; col < cols; ++col)
{
temp_ptr = &((uchar*)(img->imageData + (img->widthStep*row)))[col];
for(j=-1,ki=0; j<=1;j++,ki++)
{
for(i=-1,kj=0; i<=1;i++,kj++)
{
int x2=col+i;
int y2=row+j;
if (x2>=0 && x2<img->width && y2>=0 && y2<img->height)
{
sum=sum+k[ki][kj];
if (sum<0) sum=0; else if (sum>255) sum=255;
temp_ptr[0] =(uchar) sum;
}
}
}
}
}
}
我所知道的输出实际上取决于我的算法,但看代码和输出我会要求一些指导我应该进一步解决我的问题。
我应该在哪里放置它? –
再向下两行。看着它,我现在看到“temp_ptr [0] =(uchar)sum;”出于性能原因,应该真的下降四行。 –
这并没有改变我的形象.. –