Lab颜色空间

转载于:https://blog.csdn.net/u014395105/article/details/31753329

一、Lab颜色空间概念

Lab是一种色彩空间,也即一种颜色模型,是在1931年国际照明委员会(CIE)制定的颜色度量国际标准的基础上建立的,在1976年又经修订并被命名为CIELab.它包括人眼所能看到的所有的颜色(可见光谱),所以也是目前为止色域最宽的色彩空间,其每一组色值对应一种确定的与设备无关的色彩.这种用数学理论量化的色彩空间使不同设备的色彩能够相互比较、模拟和匹配.

在Lab颜色空间中,一种颜色由L(明度)、a颜色、b颜色三种参数表征.在一幅图像中,每一个像素有对应的Lab值.一幅图像就有对应的L通道、a通道和b通道.在Lab中,明度和颜色是分开的, L通道没有颜色,a通道和b通道只有颜色.不像在RGB颜色空间中,R通道、G通道、B通道每一个既包含有明度又包含有颜色. L取值为0–100(纯黑–纯白)、a取值为+127–128(洋红–绿)、b取值为+127–128(黄–蓝).正为暖色,负为冷色.
二、Lab颜色模式的特点 
1. Lab颜色空间中明度和颜色是分开的, L通道没有颜色,a通道和b通道只有颜色。
2.在Lab中进行调节很简单,速度很快. 
3.色域宽阔 。它不仅包含了RGB,CMYK的所有色域,还能表现它们不能表现的色彩,人的肉眼能感知的色彩,都能通过Lab 模型表现出来. 
4.它弥补了RGB色彩模型和CMYK色彩模式色彩分布不均的不足. 
三、颜色空间转换

将RGB格式转换为Lab模式有两种方法.一种是传统的图像->模式->Lab颜色;另一种是编辑->转换为配置文件,源空间配置文件:sRGB,设目的配置文件: Lab颜色,这种方法的好处是可以不勾选:使用仿色和拼合图层.转换为Lab格式时,Lab格式中的L值是按绿色60%、红色30%、蓝色10%平均而得.

以下是Android中如何在LAB空间中显示各通道的直方图的示例代码: ```java import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.series.BarGraphSeries; import com.jjoe64.graphview.series.DataPoint; public class MainActivity extends AppCompatActivity { private ImageView imageView; private GraphView graphView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = findViewById(R.id.imageView); graphView = findViewById(R.id.graphView); // 加载图片 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test); // 将图像转换为LAB空间 int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; float[] lab = new float[3]; float[] lValues = new float[256]; float[] aValues = new float[256]; float[] bValues = new float[256]; for (int i = 0; i < pixels.length; i++) { int pixel = pixels[i]; int r = Color.red(pixel); int g = Color.green(pixel); int b = Color.blue(pixel); // 转换为LAB空间 Color.RGBToLAB(r, g, b, lab); int l = (int) Math.floor(lab[0]); int a = (int) Math.floor(lab[1]); int b1 = (int) Math.floor(lab[2]); // 计算直方图 lValues[l]++; aValues[a + 128]++; bValues[b + 128]++; } // 创建直方图 BarGraphSeries<DataPoint> lSeries = new BarGraphSeries<>(getHistogramData(lValues)); BarGraphSeries<DataPoint> aSeries = new BarGraphSeries<>(getHistogramData(aValues)); BarGraphSeries<DataPoint> bSeries = new BarGraphSeries<>(getHistogramData(bValues)); // 设置直方图颜色 lSeries.setColor(Color.BLACK); aSeries.setColor(Color.RED); bSeries.setColor(Color.BLUE); // 显示直方图 graphView.addSeries(lSeries); graphView.addSeries(aSeries); graphView.addSeries(bSeries); // 显示图像 imageView.setImageBitmap(bitmap); } private DataPoint[] getHistogramData(float[] values) { DataPoint[] dataPoints = new DataPoint[values.length]; for (int i = 0; i < values.length; i++) { dataPoints[i] = new DataPoint(i, values[i]); } return dataPoints; } } ``` 需要注意的是,以上示例代码使用了第三方库GraphView来显示直方图,需要在build.gradle中添加以下依赖项: ```groovy implementation 'com.jjoe64:graphview:4.2.2' ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值