本文主要介绍高斯模糊的捷径(如何高斯模糊),下面一起看看高斯模糊的捷径(如何高斯模糊)相关资讯。
带裁剪区域的高斯模糊函数的升级版本。
函数check_rect是处理剪辑区域矩形。如果你不 t计划剪切,只需将left,top,right,bottom设置为0;另外,位图的存储格式是上下颠倒的。如果是正常裁剪,只需要设置bottom to bottom即可。
bool check_rect(int width,int height,int left,int top,int right,int bottom){ if(!向左!顶!对!bottom) {//无剪裁左= 0;top = 0;右=宽度;底部=高度;返回true}如果(!(右-左)||!(bottom-top)) {//0面积矩形返回false} if(bottom = 0) {//上下反转int h =-bottom-top;底部=高度-顶部;top = bottom-h;} if(right = 0) {//反转左右int w =-right-left;右=宽-左;左=右-w;} left = max(left,0);top = max(top,0);right = min(右,宽);bottom = min(底部,高度);返回true}//快速高斯模糊函数,由sdragonx 2014-08-01 int gauss _ blur(byte _ t * image,//bitmap data int linebytes,// bitmap row bytes,bmp数据在windows中是4字节对齐的。否则处理非二次图像会有偏差,比如int width,// bitmap width int height,// bitmap height int cbyte,//number of color channel int left,// filter clipping area,都是0,表示不裁剪int top,int right,int bottom,float sigma//gaussian coefficient){ int x = 0,y = 0,n =0;int channel = 0;int srcline = 0,dst line = 0;int channel size = 0;int bufsize = 0;float *w1 = null,*w2 = null,* imgbuf = nullint time = 0;# if defined(_ inc _ windows)time = gettickcount;#elif定义的(_ clock _ t)time = clock;# endif if if(!check_rect(width,height,left,top,right,bottom)){ return-1;}//裁剪宽度和高度int rc _ width = right-left;int rc _ height = bottom-top;channel size = rc _ width * rc _ height;bufsize = rc_width rc_height?rc _ width 4 : rc _ height 4;w1 =(float *)malloc(bufsize * sizeof(float));如果(!w1){ return-1;} w2 =(float *)malloc(buf size * sizeof(float));如果(!w2){ free(w1);return-1;} imgbuf =(float *)malloc(channel size * sizeof(float));如果(!img buf){ free(w1);免费(w2);return-1;}// -计算高斯核。浮点q2 = 0,q3 = 0;浮点b0 = 0,b1 = 0,b2 = 0,b3 = 0;浮点b = 0;if(sigma = 2.5f){ q = 0.98711 f * sigma-0.96330 f;} else if((sigma = 0.5f)(sigma 2.5f)){ q = 3.97156f - 4.14554f *(浮点)sqrt(1.0f-0.26891 f * sigma);} else { q = 0.1147705018520355224609375 f;} q2 = q * = q * q2b0 =(1.57825 f(2.44413 f * q)(1.4281 f * q2)(0.422205 f * q3));b1 =((2.44413 f * q)(2.85619 f * q2)(1.26661 f * q3));b2 =(-((1.4281 f * q2)(1.26661 f * q3));b3 =((0.422205 f * q3));b = 1.0f-((b1 b2 b3)/b0);b1/= b0;b2/= b0;b3/= b0;// -计算高斯核的结尾。通道cbytechannel) {//获取一个通道的所有像素值,预处理src line = top * line bytes left * cbyte channel;dst line = 0;for(y = 0;yrc _ heighty,srcline =linebytes,dstline =rc_width) { for(x=0,n = 0;xrc _ widthx,n = cbyte){(img buf dstline)[x]= float((image src line)[n]);} } for(int x = 0;xrc _ widthx) {//横向处理w1[0]=(img buf x)[0];w1[1]=(img buf x)[0];w1[2]=(img buf x)[0];for (y=0,n = 0;yrc _ heighty,n = rc _ width){ w1[y 3]= b *(imgbuf x)[n](b1 * w1[y 2]b2 * w1[y 1]b3 * w1[y 0]);} w2[rc _ height 0]= w1[rc _ height 2];w2[rc_h八1]= w1[rc _ height 1];w2[rc _ height 2]= w1[rc _ height 0];for (int y=rc_height-1,n = y * rc _ widthy = 0;- y,n-= rc _ width){(img buf x)[n]= w2[y]= b * w1[y 3](b1 * w2[y 1]b2 * w2[y 2]b3 * w2[y 3]);} }//横向处理src line = 0;dst line = top * line bytes left * cbyte channel;for(y = 0;yrc _ heighty,src line = rc _ width,dst line = line bytes){//纵向处理//取当前行数据w1[0]=(imgbuf src line)[0];w1[1]=(img buf src line)[0];w1[2]=(img buf src line)[0];//三点数据正向水平处理for(x = 0;xrc _ widthx){ w1[x 3]= b *(img buf srcline)[x](b1 * w1[x 2]b2 * w1[x 1]b3 * w1[x 0]);} w2[rc _ width 0]= w1[rc _ width 2];w2[rc _ width 1]= w1[rc _ width 1];w2[rc _ width 2]= w1[rc _ width 0];//逆向处理for (x=rc_width-1,n = x * cbytex = 0;- x,n-= cbyte){//(img buf srcline)[x]= w2[x]= b * w1[x 3](b1 * w2[x 1]b2 * w2[x 2]b3 * w2[x 3]);(image dst line)[n]= w2[x]= b * w1[x 3](b1 * w2[x 1]b2 * w2[x 2]b3 * w2[x 3]);} }//纵向处理/*/存储处理后的通道for(int y = 0;yrc _ heighty){ int dst line =(y top)* line bytes left * cbyte;我nt srcline = y * rc _ widthfor (int x=0,n =通道;xrc _ widthx,n = cbyte){(image dst line)[n]=(imgbuf src line)[x];//byte _ edge((img buf src line)[x]);} }//存储循环/*/}/通道循环空闲(w1);w1 =空;免费(w2);w2 = null免费(imgbuf);imgbuf = null#if defined(_inc_windows)返回gettickcount-time;#elif定义的(_clock_t)返回clock-time;#else返回0;# endif } int gauss _ blur(byte _ t * image,//位图数据int linebytes,//位图row bytes,bmp数据在windows中4字节对齐。否则在处理非二次图像时会出现偏差int width,//位图width int height,//位图height int cbyte,//颜色通道数float sigma //高斯系数){return gauss _ blur (image,line bytes,width,height,cbyte,0,0,0,sigma);}
下面是剪辑效果图:
文章发表于2014年8月14日14 : 53 : 35 csdn,现转博客花园。
标签:
位图剪辑
了解更多高斯模糊的捷径(如何高斯模糊)相关内容请关注本站点。