图像特效之随机滤波(Randomblue)
来源:互联网 发布:大学生网络诈骗统计图 编辑:程序博客网 时间:2024/06/02 05:46
图像特效之随机滤波(Randomblue)
RandomBlue----图像中随机滤波,即在图像范围内,随机获取某一范围,在该范围内以一定半径进行平均滤波处理。
关键代码:
int Randblur(IMAGE_TYPE *bmp_img,int m_iAmount,int m_iRadius,int m_iSize){DWORD width,height,dst_index;WORD biBitCount;T_U8 *bmp_data,*Result_img;T_U32 line_byte;DWORD i,j,k,l;DWORD x,y;// beginning coord (random)DWORD ex,ey; // end coord (from beginning)int rad;// blur radius (bluriness)int RAD; // total num pix processed per block int rad2; // half of the radiusint numBlurs,BytePerPixel = 3;float R,G,B,Tmp;BITMAPFILEHEADER bf;BITMAPINFOHEADER bi;FILE *Random_Blue_fp = fopen("Random_Blue_BMP.bmp","wb");if(NULL == Random_Blue_fp){printf("Can't open Random_Blue_BMP.bmp\n");return -1;}memset(&bf, 0, sizeof(bf));memset(&bi, 0, sizeof(bi));memcpy(&bf,bmp_img,14);memcpy(&bi,&bmp_img[14],40);height = bi.biHeight;width = bi.biWidth;biBitCount = bi.biBitCount;//每一个像素由24 bits表示,即RGB分量每一个分量用8 bits表示line_byte =(width*3+3) & ~0x3;fwrite(&bf,sizeof(BITMAPFILEHEADER),1,Random_Blue_fp);fwrite(&bi,sizeof(BITMAPINFOHEADER),1,Random_Blue_fp);rad = m_iRadius;RAD = rad*rad;rad2 = rad/2;Result_img = (T_U8*)malloc(height*line_byte);if(Result_img == NULL){printf("Can't malloc for result ingage.\n");return -1;}bmp_data = bmp_img + BMPHEADSIZE;memset(Result_img,0,height*line_byte);memcpy(Result_img,bmp_data,height*line_byte);for(numBlurs= 0;numBlurs < m_iAmount;numBlurs++){do{y = (int)(rand() * ((double)height / RAND_MAX));x = (int)(rand() * ((double)width / RAND_MAX));ex = x + m_iSize - 1;ey = y + m_iSize - 1;} while (ex >= width || ey >= height); for (i = y + rad2; i < ey - rad2; i++){for (j = x + rad2; j < ex - rad2; j++){dst_index = i*line_byte+3*j;R = G = B = 0;for (k = 0; k < rad; k++){for (l = 0; l < rad; l++){R += (float)bmp_data[(i+k-rad2)*line_byte+(j+l-rad2)*3+2];G += (float)bmp_data[(i+k-rad2)*line_byte+(j+l-rad2)*3+1];B += (float)bmp_data[(i+k-rad2)*line_byte+(j+l-rad2)*3];}}Result_img[dst_index] = CLIP255((int)(B/RAD));Result_img[dst_index+1] = CLIP255((int)(G/RAD));Result_img[dst_index+2] = CLIP255((int)(R/RAD));}}}fwrite(Result_img, line_byte*height*sizeof(T_U8), 1, Random_Blue_fp); fclose(Random_Blue_fp); free(Result_img);return 0;}
实际结果:
左侧为原始图,右侧围随机滤波之后的图像
阅读全文
0 0
- 图像特效之随机滤波(Randomblue)
- 图像特效之径向滤波
- java 图像特效之随机光晕
- opencv之 图像滤波
- 图像特效之水彩特效
- 图像特效之灯光特效
- 图像特效之挤压特效
- 图像特效之波浪特效
- 图像特效之浮雕(OpenCV)
- 图像特效之毛玻璃(扩散)
- 图像特效之电影海报
- 图像特效之连环画
- 图像特效之马赛克
- 图像特效之漩涡
- 图像滤波之高斯滤波介绍
- java 图像特效之图像混合(溶图)
- 图像滤波(转载)
- 图像滤波(2)
- 【洛谷1119】灾后重建
- Leetcode代码学习周记——Two Sum
- 代码传递信息方式的探究
- struts2框架浅析
- 周末训练笔记+2017 ACM/ICPC Asia Regional Shenyang Online(9.10)
- 图像特效之随机滤波(Randomblue)
- 软考之探路:大纲
- leetcode 673. Number of Longest Increasing Subsequence
- HashMap实现原理及源码分析
- maven 构建项目时,modules子模块,module对应name中的字段
- 二叉树中出现的错误
- HDU 6205:card card card
- 计蒜客16 爬楼梯 动态规划入门
- Hdu6197 array array array