图像调整亮度饱和度 c语言,图像处理之调整亮度与饱和度
图像处理之调整亮度与饱和度
什么是亮度:
简单点说一幅图像的亮度属性是图像的RGB值的大小,RGB各个值越大亮度越高RGB
分量取值范围为0~255之间。调整图像亮度。
什么是饱和度:
饱和度是是指颜色的强度,调整饱和度可以修正过度曝光或者未充分曝光的图片。使
图像看上去更加自然。
基本思想:
通常在RGB色彩空间调整亮度与饱和度不是很直观,而HSL彩色空可以很直观表示出
每个像素的饱和度与亮度。所以首先读取图像的像素RGB值然后再转换到HSL空间得
到饱和度与亮度值,调整以后再从HSL空间转换到RGB空间的RGB值,对每个像素完
成这样的调整就完成图像的亮度与饱和度调整。关于RGB与HSL色彩空间的转换
看这里:http://en.wikipedia.org/wiki/HSL_color_space
程序效果:
滤镜源代码:
package com.gloomyfish.filter.study; import java.awt.image.BufferedImage; /** * http://en.wikipedia.org/wiki/HSL_color_space * @author gloomy fish * @date 2012-09-26 * */ public class HSLFilter extends AbstractBufferedImageOp { public final static double c1o60 = 1.0 / 60.0; public final static double c1o255 = 1.0 / 255.0; private double hue; private double saturation; private double lightness; public HSLFilter() { System.out.println("Hue Filter"); } public double getHue() { return hue; } public void setHue(double hue) { while (hue < 0.0) { this.hue += 360; } while (hue >= 360.0) { this.hue -= 360; } } public double getSaturation() { return saturation; } public void setSaturation(double saturation) { if((saturation >= -100.0) && (saturation <= 100.0)) { this.saturation = saturation; } } public double getLightness() { return lightness; } public void setLightness(double lightness) { if((lightness >= -100.0) && (lightness <= 100.0)) { this.lightness = lightness; } } @Override public BufferedImage filter(BufferedImage src, BufferedImage dest) { int width = src.getWidth(); int height = src.getHeight(); double sat = 127.0d * saturation / 100.0d; double lum = 127.0d * lightness / 100.0d; if ( dest == null ) dest = createCompatibleDestImage( src, null ); int[] inPixels = new int[width*height]; int[] outPixels = new int[width*height]; getRGB( src, 0, 0, width, height, inPixels ); double min, max, dif, sum; double f1, f2; int index = 0; double h, s, l; double v1, v2, v3, h1; for(int row=0; row> 24) & 0xff; tr = (inPixels[index] >> 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; // convert to HSL space min = tr; if (tg < min) min = tg; if (tb < min) min = tb; max = tr; f1 = 0.0; f2 = tg - tb; if (tg > max) { max = tg; f1 = 120.0; f2 = tb - tr; } if (tb > max) { max = tb; f1 = 240.0; f2 = tr - tg; } dif = max - min; sum = max + min; l = 0.5 * sum; if (dif == 0) { h = 0.0; s = 0.0; } else if(l < 127.5) { s = 255.0 * dif / sum; } else { s = 255.0 * dif / (510.0 - sum); } h = (f1 + 60.0 * f2 / dif); if (h < 0.0) { h += 360.0; } if (h >= 360.0) { h -= 360.0; } // Apply transformation. h = h + hue; if( h >= 360.0) { h = h - 360.0; } s = s + sat; if( s < 0.0) { s = 0.0; } if( s > 255.0) { s = 255.0; } l = l + lum; if( l < 0.0) { l = 0.0; } if( l > 255.0) { l = 255.0; } // conversion back to RGB space here!! if (s == 0) { tr = (int)l; tg = (int)l; tb = (int)l; } else { if (l < 127.5) { v2 = c1o255 * l * (255 + s); } else { v2 = l + s - c1o255 * s * l; } v1 = 2 * l - v2; v3 = v2 - v1; h1 = h + 120.0; if (h1 >= 360.0) h1 -= 360.0; if (h1 < 60.0) { tr = (int)(v1 + v3 * h1 * c1o60); } else if (h1 < 180.0) { tr = (int)v2; } else if (h1 < 240.0) { tr = (int)(v1 + v3 * (4 - h1 * c1o60)); } else { tr = (int)v1; } h1 = h; if (h1 < 60.0) { tg = (int)(v1 + v3 * h1 * c1o60); } else if (h1 < 180.0) { tg = (int)v2; } else if (h1 < 240.0) { tg = (int)(v1 + v3 * (4 - h1 * c1o60)); } else { tg = (int)v1; } h1 = h - 120.0; if (h1 < 0.0) { h1 += 360.0; } if (h1 < 60.0) { tb = (int)(v1 + v3 * h1 * c1o60); } else if (h1 < 180.0) { tb = (int)v2; } else if (h1 < 240.0) { tb = (int)(v1 + v3 * (4 - h1 * c1o60)); } else { tb = (int)v1; } } outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb; } } setRGB( dest, 0, 0, width, height, outPixels ); return dest; } }转载请务必注明出处,
图像调整亮度饱和度 c语言,图像处理之调整亮度与饱和度相关推荐
- 图像处理之调整亮度与饱和度
图像处理之调整亮度与饱和度 什么是亮度: 简单点说一幅图像的亮度属性是图像的RGB值的大小,RGB各个值越大亮度越高RGB 分量取值范围为0-255之间.调整图像亮度. 什么是饱和度: 饱和度是是指颜 ...
- 数字图像处理课设图像的锐化_数字图像处理图像锐化处理.ppt
数字图像处理图像锐化处理 4.7.2 灰度级到彩色转换 灰度级到彩色转换(例) 在HSI彩色空间的直方图均衡强度均衡处理没有改变图像的色调和饱和度值,但它的确影响了整体图像的彩色感观. 向量分量可以用 ...
- c语言中图像处理相关函数,C语言图像处理函数大全
C语言图像处理函数 没有积分,无私奉献,只希望多多支持,哈哈谢谢了 C语言图像处理函数大全,完整版 1.图像平移 图像平移只是改变图像在屏幕上的位置,图像本身并不发生变化. 假设原图像区域左上角坐标为 ...
- 【计算视觉】理解图像中基本概念:色调、色相、饱和度、对比度、亮度
理解图像中基本概念:色调.色相.饱和度.对比度.亮度 对比度: 对比度指不同颜色之间的差别.对比度越大,不同颜色之间的反差越大,即所谓黑白分明,对比度过大,图像就会显得很刺眼.对比度越小,不同颜色之间 ...
- VS+OpenCV 处理图像的颜色(下)用色调、饱和度和亮度表示颜色、肤色检测
[实现] #include<opencv2/core.hpp> #include<opencv2/highgui.hpp> #include<opencv2/imgpro ...
- c语言 读取 256级 灰度 bmp,256级灰度BMP文件读写源代码c语言图像处理.doc
256级灰度BMP文件读写源代码c语言图像处理 本文档最早发布于 /u/1495182054 1.256级灰度BMP文件读写的源代码! 首先要明白256级灰度BMP文件的格式 1.首先是一个14个字节 ...
- bmp灰度图像的c语言读,256级灰度BMP文件读写的源代码+c语言图像处理.doc
256级灰度BMP文件读写的源代码c语言图像处理 恬鸥津酶澡硷颈晌堕耀贱剃记揉老硝喂及谨总卧真宁谎桐危擦抽电狰侯亚智搏椅捣尾捐包嚎穿湛嚏焉队柏拽砾桃潍詹矢钟候拙伪蜜邪有说栖站掠恒吻蔽矾亏玲坎谬溜巷疵悍 ...
- 图像调整亮度饱和度 c语言,【C#/WPF】调节图像的HSL(色相、饱和度、明亮度)...
先说概念: HSL是一种描述颜色的方式(其他颜色描述方式还有大家熟悉的RGB值).HSL三个字母分别表示图像的Hue色相.Saturation饱和度.Lightness明亮度. 需求: 制作一个面板, ...
- 图像调整亮度饱和度 c语言,数据增强-亮度-对比度-色彩饱和度-色调-锐度 不改变图像大小...
# coding=utf-8 import os import os import cv2 import math import numpy as np from PIL import Image f ...
最新文章
- JSP与ASP的比较
- jpa query 取数组第一个_数据结构基础-数组
- 在Chrome插件上获取当前插件的版本号
- 安防监控产业链全景梳理
- mysql中基本的DDL语句(关注一下,以后会继续更新喔!)
- CNN卷积神经网络(吴恩达《卷积神经网络》笔记一)
- 游戏软件性能测试怎么做?常规测试知识要点总结
- transform3D转换
- 【Arcpy】Python in ArcGIS
- mysql插入datetime默认值0000-00-00时报错
- 系统级程序设计结课实验-第一部分
- Ubuntu20.04+i3wm折腾笔记
- 模板函数与模板参数自动推导
- kindle索引_kindle索引一般多久
- 知乎App产品体检报告
- 51单片机交通灯(定时器+38译码器+中断)
- 为什么开发与测试老掐架呢
- MoveIt!入门教程-简介
- C语言让程序自己获得管理员权限
- error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\link.exe' failed wit