日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图像调整亮度饱和度 c语言,图像处理之调整亮度与饱和度

發布時間:2023/12/8 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像调整亮度饱和度 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语言,图像处理之调整亮度与饱和度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。