对图像进行滤镜(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>

原图:

一、反色特效:


二、浮雕特效:


三、雕刻特效:


四、怀旧特效:


五、冰冻特效:


六、暗调特效:


图像滤镜特效(反色、浮雕、雕刻、怀旧、冰冻、暗调)(一)相关推荐

  1. Java图片gh颜色渐变_强大的Java图像滤镜特效类库Java Image Filters

    Java Image Filters是一款基于Java的图像处理类库,特别是在图像滤镜特效方面,Java Image Filters简直就是强大到天衣无缝.它几乎提供了PS上大部分的图像特效.比如反色 ...

  2. 图像滤镜艺术---霓虹、浮雕、木刻滤镜

    图像滤镜艺术---霓虹.浮雕.木刻滤镜 原文:图像滤镜艺术---霓虹.浮雕.木刻滤镜 图像特效往往可以将普通的照片呈现出一种令人耳目一新的效果,特效的种类繁多,比如各种流行的 滤镜特效等等,今天,我们 ...

  3. canvas--putImageData--(灰色滤镜、黑白滤镜、反色滤镜、模糊滤镜、马赛克滤镜)

    示例 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title& ...

  4. [Python图像处理] 三十三.图像各种特效处理及原理万字详解(毛玻璃、浮雕、素描、怀旧、流年、滤镜等)...

    此文转载自:https://blog.csdn.net/Eastmount/article/details/111568397#commentBox 该系列文章是讲解Python OpenCV图像处理 ...

  5. [Python图像处理] 二十五.图像特效处理之素描、怀旧、光照、流年以及滤镜特效

    该系列文章是讲解Python OpenCV图像处理知识,前期主要讲解图像入门.OpenCV基础用法,中期讲解图像处理的各种算法,包括图像锐化算子.图像增强技术.图像分割等,后期结合深度学习研究图像识别 ...

  6. 【Python】图像反转/反色的三种方法(pillow)

    引言 图像反转(反色)是将图像的灰度值反转,若图像灰度级为 256,则新图的灰度值为 255 减去原图的灰度值.本文介绍了使用 Python 的 pillow 库进行图像反转(反色)的三种方法. 安装 ...

  7. python图像处理方法_python图像处理之反色实现方法

    本文实例讲述了python图像处理之反色实现方法.分享给大家供大家参考.具体如下: 我们先加载一个8位灰度图像 每一个像素对应的灰度值从0-255 则只需要读取每个像素的灰度值A,再将255-A写入 ...

  8. 图像处理软件开发记录(六) 图像特效(浮雕、怀旧)

    专栏地址:http://blog.csdn.net/column/details/imagep.html 本篇文章主要记录一下图像处理软件中的图像特效(浮雕.怀旧)的实现过程. 图像浮雕效果 浮雕的算 ...

  9. Matlab编程实现图像滤镜效果(浮雕、怀旧色、连环画、羽化、素描、强光等)

    Matlab编程实现图像滤镜效果 实验的目的是按照PhotoShop中实现滤镜效果的步骤进行matlab程序编码,最后实现相应的滤镜效果.主要包含的滤镜效果有:浮雕效果.怀旧色风格.连环画效果.交叉冲 ...

最新文章

  1. 第七章-NoSQL数据库
  2. 【软考-软件设计师】计算机系统知识概览
  3. TensorFlow 2.0 快速上手教程与手写数字识别例子讲解
  4. 理解android.intent.action.MAIN 与 android.intent.category.LAUNCHER
  5. nginx+php-fpm页面显示空白的解决方法
  6. Django的url别名功能的使用
  7. os.path.join;os.makedirs()
  8. 第三百四十五天 how can I 坚持
  9. bootstrap table背景_bootstrap table给行怎么加背景色
  10. STM32F4之SDIO接口
  11. 除了努力挣钱,青春也不能错过的十件事
  12. CSDN博客图片服务器异常的艰辛排查与处理-上传文件时发生 HTTP 错误(错误代码:502)的解决办法
  13. 红旗h5中控台恢复出厂设置后不显示倒车影像问题
  14. ES可视化工具--Dejavu--下载、安装、使用
  15. CF643D Bearish Fanpages
  16. 从前慢-项目小型秒杀系统
  17. html中加大字体,html字体加大标签与写法介绍
  18. STM32CubeMX入门使用一
  19. 自动白平衡技术(WhiteBalance)(转自Harri的blog)
  20. 微信工具(Python)实现备注管理和群发消息

热门文章

  1. RK3399平台开发系列讲解(内核驱动外设篇)6.10、CAN转SPI 控制芯片MCP2515设备树配置
  2. 发布租房信息html模板,个人房屋出租怎么写 发布租房信息的注意事项
  3. Spring AOP理论 +代理模式详解
  4. Wise Care 365 PRO v5.5.4.549 绿色特别版
  5. 2020年8月虹科Pico汽车示波器简报
  6. 数据仓库推荐经典书籍资料包分享
  7. 如何从0基础到安卓软件开发工程师?
  8. 全国中小学教师计算机水平考试,全国中小学教师教育技术水平考试网
  9. 弹塑性力学复习及整理(思维所致,随时更新)
  10. 资深java工程师简历