图像滤镜特效(反色、浮雕、雕刻、怀旧、冰冻、暗调)(一)
来源:互联网 发布:java和前端哪个招的多 编辑:程序博客网 时间:2024/04/28 06:54
对图像进行滤镜(PS中的叫法)特效处理完全是导师的要求,现把工作整理出来(效果图见最后)。
一、反色特效
反色特效原理比较简单,就是分别把RGB通道的像素值取反即可。
下面是反色特效VC++程序:
<span style="font-size:14px;">/*************************************************************************** 函数名称:* Negative(LPBYTE lpDIBBits, LPSTR lpDIB, LONG lWidth, LONG lHeight)** 参数:* lpDIBBits - 原始图像的像素指针* lWidth - 原始图像的宽度* lHeight - 原始图像的高度*** 说明:* 实现图像的反色效果。*************************************************************************/BOOL WINAPI Negative(LPBYTE lpDIBBits, LPSTR lpDIB, LONG lWidth, LONG lHeight){// 颜色表中的颜色数目DWORD wNumColors;//DWORD位32位无符号整型// 获取DIB中颜色表中的颜色数目 //DIBNumColors()该函数返回DIB中调色板的颜色的种数。对于单色位图,返回2,对于16色位图,返回16,// 对于256色位图,返回256;对于真彩色位图(24位),没有调色板,返回0。wNumColors = ::DIBNumColors(lpDIB);unsigned char *lpSrc;LONG i, j;int buf;if (wNumColors == 256){LONG lLineBytes = WIDTHBYTES(lWidth * 8);for (i = lHeight; i >= 1; i--){for (j = lWidth; j >= 0; j--){buf = 255 - *((unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j);lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j;*lpSrc = (unsigned char)buf;}}}else if (wNumColors == 0){LONG lLineBytes = WIDTHBYTES(lWidth * 24);for (i = lHeight; i >= 1; i--){for (j = lWidth * 3; j >= 0; j--){buf = 255 - *((unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j);lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j;*lpSrc = (unsigned char)buf;}}}else{MessageBox(NULL, TEXT("不支持此类型位图!"), TEXT("系统提示"), MB_ICONINFORMATION | MB_YESNO);}return TRUE;}</span>
二、浮雕特效
浮雕图像效果是指图像的前景前向凸出背景。所谓的“浮雕”处理是指图像上的一个像素和它左上方的那个像素之间的差值的一种处理过程,为了使图像保持一定的亮度并呈现灰色,在处理过程中为这个差值加上一个数值为128的常量,需要注意的是,当设置一个像素值的时候,它和它的左上方的像素都要被用到,为了避免用到已经设置过的像素,应该从图像的右下方的像素开始处理,这样还会出现一个问题就是图像最左方和最上方的没有得到处理,这里我把它们的像素值设为128。
下面是浮雕特效VC++程序:
<span style="font-size:14px;">/*************************************************************************** 函数名称:* Emboss(LPBYTE lpDIBBits, LPSTR lpDIB, LONG lWidth, LONG lHeight)** 参数:* lpDIBBits - 原始图像的像素指针* lWidth - 原始图像的宽度* lHeight - 原始图像的高度*** 说明:* 实现图像的浮雕效果。*************************************************************************/BOOL WINAPI Emboss(LPBYTE lpDIBBits, LPSTR lpDIB, LONG lWidth, LONG lHeight){// 颜色表中的颜色数目DWORD wNumColors;//DWORD位32位无符号整型// 获取DIB中颜色表中的颜色数目 //DIBNumColors()该函数返回DIB中调色板的颜色的种数。对于单色位图,返回2,对于16色位图,返回16,// 对于256色位图,返回256;对于真彩色位图(24位),没有调色板,返回0。wNumColors = ::DIBNumColors(lpDIB);unsigned char *lpSrc;LONG i, j;int buf;if (wNumColors == 256){LONG lLineBytes = WIDTHBYTES(lWidth * 8);//24表示24位真彩色图像for (i = lHeight; i >= 2; i--){for (j = lWidth; j >= 2; j--){buf = *((unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j) -*((unsigned char*)lpDIBBits + lLineBytes*(lHeight - i + 1) + j - 1) + 128; //j - 3 if (buf<0) {buf = 0;}if (buf>255) {buf = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j;*lpSrc = (unsigned char)buf;}}for (i = 0; i < lWidth; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - 0) + i;*lpSrc = 128;}for (i = 0; i < lHeight; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + 0;*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + 1;*lpSrc = 128;}}else if (wNumColors == 0){LONG lLineBytes = WIDTHBYTES(lWidth * 24);//24表示24位真彩色图像for (i = lHeight; i >= 2; i--){for (j = lWidth * 3; j >= 2; j--){buf = *((unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j) -*((unsigned char*)lpDIBBits + lLineBytes*(lHeight - i + 1) + j - 3) + 128; if (buf<0) {buf = 0;}if (buf>255) {buf = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - i) + j;*lpSrc = (unsigned char)buf;}}for (i = 0; i < lWidth * 3; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - 0) + i;*lpSrc = 128;}for (i = 0; i < lHeight; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + 0;*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + 1;*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + 2;*lpSrc = 128;}}else{MessageBox(NULL, TEXT("不支持此类型位图!"), TEXT("系统提示"), MB_ICONINFORMATION | MB_YESNO);}return TRUE;}</span>
三、雕刻特效
雕刻效果与浮雕效果类似,不同之处是雕刻效果的处理过程是取一个像素和它右下方的像素之间的差值再加上一个常数128,这时的图像的前景凹陷进背景之中,同样需要注意的是为了避免重复使用处理过的图像像素,处理图像时要从图像的左上方的像素开始处理,而且把没有处理过的像素值设为128。
下面是雕刻特效VC++程序:
/*************************************************************************** 函数名称:* Engrave(LPBYTE lpDIBBits, LPSTR lpDIB, LONG lWidth, LONG lHeight)** 参数:* lpDIBBits - 原始图像的像素指针* lWidth - 原始图像的宽度* lHeight - 原始图像的高度*** 说明:* 实现图像的雕刻效果。*************************************************************************/BOOL WINAPI Engrave(LPBYTE lpDIBBits, LPSTR lpDIB, LONG lWidth, LONG lHeight){// 颜色表中的颜色数目DWORD wNumColors;//DWORD位32位无符号整型// 获取DIB中颜色表中的颜色数目 //DIBNumColors()该函数返回DIB中调色板的颜色的种数。对于单色位图,返回2,对于16色位图,返回16,// 对于256色位图,返回256;对于真彩色位图(24位),没有调色板,返回0。wNumColors = ::DIBNumColors(lpDIB);unsigned char *lpSrc;LONG i, j;int buf;if (wNumColors == 256){LONG lLineBytes = WIDTHBYTES(lWidth * 8);//24表示24位真彩色图像for (i = 0; i <= lHeight - 2; i++){for (j = 0; j <= (lWidth - 2) * 1; j++){buf = *((unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j) -*((unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i - 1) + j + 1) + 128;if (buf<0) {buf = 0;}if (buf>255) {buf = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = (unsigned char)buf;}}for (i = 0; i < lWidth; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes * 0 + i;*lpSrc = 128;}for (i = 0; i < lHeight; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + lWidth - 1;*lpSrc = 128;}}else if (wNumColors == 0){LONG lLineBytes = WIDTHBYTES(lWidth * 24);//24表示24位真彩色图像for (i = 0; i <= lHeight - 2; i++){for (j = 0; j <= (lWidth - 2) * 3; j++){buf = *((unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j) -*((unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i - 1) + j + 3) + 128;if (buf<0) {buf = 0;}if (buf>255) {buf = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = (unsigned char)buf;}}for (i = 0; i < lWidth * 3; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes * 0 + i;*lpSrc = 128;}for (i = 0; i < lHeight; i++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + (lWidth * 3 - 1);*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + (lWidth * 3 - 2);*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + (lWidth * 3 - 3);*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + (lWidth * 3 - 4);*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + (lWidth * 3 - 5);*lpSrc = 128;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + (lWidth * 3 - 6);*lpSrc = 128;}}else{MessageBox(NULL, TEXT("不支持此类型位图!"), TEXT("系统提示"), MB_ICONINFORMATION | MB_YESNO);}return TRUE;}
四、怀旧特效
怀旧特效的原理直接用下面公式表示:
下面是怀旧特效VC++程序:
/*************************************************************************** 函数名称:* ReAncient(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight)** 参数:* lpDIBBits - 原始图像的像素指针* lWidth - 原始图像的宽度* lHeight - 原始图像的高度*** 说明:* 实现图像的怀旧效果。*************************************************************************/BOOL ReAncient(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int* buf;buf = new int[lHeight * lWidth * 3];unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;buf[i*lWidth * 3 + j + 2] = (int)(0.393*(*lpRed) + 0.769*(*lpGreen) + 0.189*(*lpBlue));buf[i*lWidth * 3 + j + 1] = (int)(0.349*(*lpRed) + 0.686*(*lpGreen) + 0.168*(*lpBlue));buf[i*lWidth * 3 + j + 0] = (int)(0.272*(*lpRed) + 0.534*(*lpGreen) + 0.131*(*lpBlue));if (buf[i*lWidth * 3 + j + 2]>255){buf[i*lWidth * 3 + j + 2] = 255;}if (buf[i*lWidth * 3 + j + 2]<0){buf[i*lWidth * 3 + j + 2] = 0;}if (buf[i*lWidth * 3 + j + 1]>255){buf[i*lWidth * 3 + j + 1] = 255;}if (buf[i*lWidth * 3 + j + 1]<0){buf[i*lWidth * 3 + j + 1] = 0;}if (buf[i*lWidth * 3 + j + 0]>255){buf[i*lWidth * 3 + j + 0] = 255;}if (buf[i*lWidth * 3 + j + 0]<0){buf[i*lWidth * 3 + j + 0] = 0;}}}for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j++){lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = buf[i*lWidth * 3 + j];}}return TRUE;}
四、冰冻特效
冰冻特效的原理直接用下面公式表示:
下面是冰冻特效VC++程序:
/*************************************************************************** 函数名称:* Freeze(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight)** 参数:* lpDIBBits - 原始图像的像素指针* lWidth - 原始图像的宽度* lHeight - 原始图像的高度*** 说明:* 实现图像的冰冻效果。*************************************************************************/BOOL Freeze(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int buf1, buf2, buf3;unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;buf1 = (int)((*lpRed) - (*lpGreen) - (*lpBlue));buf1 = buf1 * 3 / 2;if (buf1<0){buf1 = -buf1;//将buf取反后buf有可能大于255,所以要将判断小于0放在判断大于255前面}if (buf1>255){buf1 = 255;}buf2 = (int)((*lpGreen) - (*lpRed) - (*lpBlue));buf2 = buf2 * 3 / 2;if (buf2<0){buf2 = -buf2;}if (buf2>255){buf2 = 255;}buf3 = (int)((*lpBlue) - (*lpGreen) - (*lpRed));buf3 = buf3 * 3 / 2;if (buf3<0){buf3 = -buf3;}if (buf3>255){buf3 = 255;}lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = buf3;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 1;*lpSrc = buf2;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 2;*lpSrc = buf1;}}return TRUE;}
五、暗调特效
暗调特效就是亮度调整的一种特殊方法。它主要通过降低图像色彩各分量中的亮度,使整幅图像变得深暗。公式如下:
下面是暗调特效VC++程序:
<span style="font-size:14px;">/*************************************************************************** 函数名称:* Shade(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight)** 参数:* lpDIBBits - 原始图像的像素指针* lWidth - 原始图像的宽度* lHeight - 原始图像的高度*** 说明:* 实现图像的暗调效果。*************************************************************************/BOOL Shade(LPBYTE lpDIBBits, LONG lWidth, LONG lHeight){unsigned char *lpSrc;LONG i, j, n;LONG lLineBytes = WIDTHBYTES(lWidth * 24);int buf1, buf2, buf3;unsigned char* lpRed;unsigned char* lpGreen;unsigned char* lpBlue;for (i = 0; i < lHeight; i++){for (j = 0; j < lWidth * 3; j += 3){lpRed = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 2;//顺序为BGRlpGreen = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j + 1;lpBlue = (unsigned char*)lpDIBBits + lLineBytes * (lHeight - 1 - i) + j;buf1 = (int)((*lpBlue)*(*lpBlue) / 300);buf2 = (int)((*lpGreen)*(*lpGreen) / 300);buf3 = (int)((*lpRed)*(*lpRed) / 300);lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j;*lpSrc = buf1;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 1;*lpSrc = buf2;lpSrc = (unsigned char*)lpDIBBits + lLineBytes*(lHeight - 1 - i) + j + 2;*lpSrc = buf3;}}return TRUE;}</span>
原图:
一、反色特效:
二、浮雕特效:
三、雕刻特效:
四、怀旧特效:
五、冰冻特效:
六、暗调特效:
0 0
- 图像滤镜特效(反色、浮雕、雕刻、怀旧、冰冻、暗调)(一)
- 图像处理软件开发记录(六) 图像特效(浮雕、怀旧)
- 学习OpenCV:滤镜系列(10)——怀旧色 & 连环画 & 熔铸 & 冰冻
- 学习OpenCV:滤镜系列(10)——怀旧色 & 连环画 & 熔铸 & 冰冻
- 实现图像特效之浮雕与雕刻
- 学习OpenCV:滤镜系列(1)—— 雕刻&浮雕
- 学习OpenCV:滤镜系列(1)—— 雕刻&浮雕
- 图像特效---怀旧风格滤镜
- 【Android图像处理】浮雕滤镜(效果)
- Android 图像处理(浮雕、复古、怀旧等)
- 图像特效之浮雕(OpenCV)
- Android图像处理(三)负片,怀旧,浮雕,灰度,圆角,油画和左右对称
- Android图像处理(二)底片效果、怀旧效果、浮雕效果
- 【图像处理】数字图像处理软件-图片特效--浮雕效果(四)
- PhotoShop算法实现进阶-浮雕滤镜-灰度浮雕(三十一)
- 图像滤镜艺术---霓虹、浮雕、木刻滤镜
- Android 浮雕遮罩滤镜(EmbossMaskFilter)
- Android 常见滤镜的实现,怀旧,底片,浮雕,ColorMatrix
- 第十四周 项目一:小玩文件(2)
- Android 强制横屏或竖屏注意事项及onConfigurationChanged的使用
- http、浏览器---工作原理讲解-----阿冬专栏!!!!
- 欢迎使用CSDN-markdown编辑器
- Navicat for Mysql 只导出数据表结构(.sql文件)的方法
- 图像滤镜特效(反色、浮雕、雕刻、怀旧、冰冻、暗调)(一)
- 123123
- 用过滤器来解决JSP中文乱码问题
- 49.关键帧动画
- Gson 字符串和json对象的转换
- JS-Web Storage
- tomcat部署项目 以及 如何去掉项目名称
- 人丑就要多读书(6)
- JS-applicationCache对象