CIELAB颜色空间中的坐标范围是多少? [英] What are the ranges of coordinates in the CIELAB color space?

查看:710
本文介绍了CIELAB颜色空间中的坐标范围是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

  public List< Tuple< double,double ,double>> GetNormalizedPixels(位图图像​​)
{
System.Drawing.Imaging.BitmapData数据= image.LockBits(
new Rectangle(0,0,image.Width,image.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
image.PixelFormat);

int pixelSize = Image.GetPixelFormatSize(image.PixelFormat)/ 8;

var result = new List< Tuple< double,double,double>>();

不安全
{
for(int y = 0; y {
byte * row =( byte *)data.Scan0 +(y * data.Stride);

for(int x = 0; x< data.Width; ++ x)
{
Color c = Color.FromArgb(
row [x * pixelSize + 3],
row [x * pixelSize + 2],
row [x * pixelSize + 1],
row [x * pixelSize]);

//(*)
结果.Add(Tuple.Create(
1.0 * cR / 255,
1.0 * cG / 255,
1.0 * cB / 255);
}
}
}

image.UnlockBits(data);

返回结果;
}

关键片段(*)是这样的:

  result.Add(Tuple.Create(
1.0 * cR / 255,
1.0 * cG / 255,
1.0 * cB / 255);

会添加一个像素,其像素缩放到范围 [0,1] 可以进一步用于具有不同分类器的分类任务中,其中一些需要像这样对属性进行规范化,而另一些则不在乎-因此此功能。



但是,当我想对不同于 RGB 的颜色空间中的像素进行分类时,我该怎么办,例如 L * a * b * RGB 颜色空间中所有坐标的ile值在 L *中的范围 [0,256)据说a * b * 颜色空间 a * b * 是无界的。



因此,当将片段(*)更改为:

  Lab lab = c.ToLab(); 

结果。Add(Tuple.Create(
1.0 * lab.L / 100,
1.0 * lab.A /?,
1.0 * lab.B / ?);

ToLab 是扩展名方法,使用此处)中的适当算法实现。



我该问些什么?

解决方案

实际上所有 RGB的数量颜色是有限的,因此 L * a * b * 的空间是有界的,可以使用以下简单程序轻松找到坐标范围:

 颜色c; 

double maxL = double.MinValue;
double maxA = double.MinValue;
double maxB = double.MinValue;
double minL = double.MaxValue;
double minA = double.MaxValue;
double minB = double.MaxValue ;(int r = 0; r <256; ++ r)的

(int g = 0; g <256; ++ g)
(int b = 0; b< 256; ++ b)
{
c = Color.FromArgb(r,g,b);

Lab lab = c.ToLab();

maxL = Math.Max(maxL,lab.L);
maxA = Math.Max(maxA,lab.A);
maxB = Math.Max(maxB,lab.B);
minL = Math.Min(minL,lab.L);
minA = Math.Min(minA,lab.A);
minB = Math.Min(minB,lab.B);
}

Console.WriteLine( maxL =" + maxL +",maxA =" + maxA +",maxB =" + maxB);
Console.WriteLine( minL = + minL +,minA = + minA +,minB = + minB);

或使用任何其他语言的类似语言。


因此, CIELAB 空间坐标范围如下:


[0,100]中的L


[-86.185,98.254]中的

A $ p $ b

[-107.863,94.482]中的b

B

答案是:

  Lab lab = c.ToLab(); 

结果。Add(Tuple.Create(
1.0 * lab.L / 100,
1.0 *(lab.A + 86.185)/ 184.439,
1.0 * (实验室B + 107.863)/ 202.345);


I have the following piece of code:

public List<Tuple<double, double, double>> GetNormalizedPixels(Bitmap image)
{
    System.Drawing.Imaging.BitmapData data = image.LockBits(
        new Rectangle(0, 0, image.Width, image.Height),
        System.Drawing.Imaging.ImageLockMode.ReadOnly,
        image.PixelFormat);

    int pixelSize = Image.GetPixelFormatSize(image.PixelFormat) / 8;

    var result = new List<Tuple<double, double, double>>();

    unsafe
    {
        for (int y = 0; y < data.Height; ++y)
        {
            byte* row = (byte*)data.Scan0 + (y * data.Stride);

            for (int x = 0; x < data.Width; ++x)
            {
                Color c = Color.FromArgb(
                    row[x * pixelSize + 3],
                    row[x * pixelSize + 2],
                    row[x * pixelSize + 1],
                    row[x * pixelSize]);

                // (*)
                result.Add(Tuple.Create(
                    1.0 * c.R / 255,
                    1.0 * c.G / 255,
                    1.0 * c.B / 255);
            }
        }
    }

    image.UnlockBits(data);

    return result;
}

The key fragment (*) is this:

result.Add(Tuple.Create(
    1.0 * c.R / 255,
    1.0 * c.G / 255,
    1.0 * c.B / 255);

which adds a pixel with its components scaled to range [0, 1] to be further used in classification tasks with different classifiers. Some of them require the attributes to be normalized like this, others don't care - hence this function.

However, what should I do when I'd like to classify pixels in a different colour space than RGB, like L*a*b*? While values of all coordinates in RGB colour space fall into range [0,256) in L*a*b* colour space a* and b* are said to be unbounded.

So when changing the fragment (*) to:

Lab lab = c.ToLab();

result.Add(Tuple.Create(
    1.0 * lab.L / 100,
    1.0 * lab.A / ?,
    1.0 * lab.B / ?);

(ToLab is an extension method, implemented using appropriate algorithms from here)

what should I put for the question marks?

解决方案

In practice the number of all possible RGB colours is finite, so the L*a*b* space is bounded. It is easy to find the ranges of coordinates with the following simple program:

Color c;

double maxL = double.MinValue;
double maxA = double.MinValue;
double maxB = double.MinValue;
double minL = double.MaxValue;
double minA = double.MaxValue;
double minB = double.MaxValue;

for (int r = 0; r < 256; ++r)
    for (int g = 0; g < 256; ++g)
        for (int b = 0; b < 256; ++b)
        {
            c = Color.FromArgb(r, g, b);

            Lab lab = c.ToLab();

            maxL = Math.Max(maxL, lab.L);
            maxA = Math.Max(maxA, lab.A);
            maxB = Math.Max(maxB, lab.B);
            minL = Math.Min(minL, lab.L);
            minA = Math.Min(minA, lab.A);
            minB = Math.Min(minB, lab.B);
        }

Console.WriteLine("maxL = " + maxL + ", maxA = " + maxA + ", maxB = " + maxB);
Console.WriteLine("minL = " + minL + ", minA = " + minA + ", minB = " + minB);

or a similar one using any other language.

So, CIELAB space coordinate ranges are as follows:

L in [0, 100]

A in [-86.185, 98.254]

B in [-107.863, 94.482]

and the answer is:

Lab lab = c.ToLab();

result.Add(Tuple.Create(
    1.0 * lab.L / 100,
    1.0 * (lab.A + 86.185) / 184.439,
    1.0 * (lab.B + 107.863) / 202.345);

这篇关于CIELAB颜色空间中的坐标范围是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆