怎样由(RGB)三原色格式中提取(ESL) 色调<色相>,饱和度,亮度数据?????
谢谢!

解决方案 »

  1.   

    用bcb做的,*r,*g,*b,分别对应R,G,B分量,
    Graphics::TBitmap* tBitmap=new Graphics::TBitmap;
    tBitmap->Assign(Image1->Picture->Bitmap);
    tBitmap->PixelFormat=pf24bit;
    for(int i=0;i<tBitmap->Height;++i)
    {
    ptr=(Byte *)tBitmap->ScanLine[i];
    for(int j=0;j<tBitmap->Width;++j)
    {
    x=float(ptr[j*3]);
    y=float(ptr[j*3+1]);
    z=float(ptr[j*3+2]);
    rgbtohls(&x,&y,&z);
    delete tBitmap;
    }
    void __fastcall TForm1::rgbtohls(float *r,float *g,float *b)
    {
    float m,n,p,q,x,y,delta,h1,l1,s1;
    *r=(1.0/256)*(*r);
    *g=(1.0/256)*(*g);
    *b=(1.0/256)*(*b);
    x=max(*r,*g);
    y=max(*g,*b);
    m=max(x,y);
    p=min(*r,*g);
    q=min(*g,*b);
    n=min(p,q);
    l1=(m+n)/2;
    if (m==n)
       {s1=0;h1=0;}
    else
       {if (l1<=0.5)
           s1=(m-n)/(m+n);
       else
           s1=(m-n)/(2-m-n);
       delta=m-n;
       if (*r==m)
           h1=(*g-*b)/delta;
       else if (*g==m)
           h1=2+(*b-*r)/delta;
       else if (*b==m)
            h1=4+(*r-*g)/delta;
        h1=h1/6;
       if (h1<0)
        h1=h1+1;
        }*r=360*h1;
    *g=360*l1;
    *b=360*s1;
    }
      

  2.   

    用bcb做的,*r,*g,*b,分别对应R,G,B分量,
    Graphics::TBitmap* tBitmap=new Graphics::TBitmap;
    tBitmap->Assign(Image1->Picture->Bitmap);
    tBitmap->PixelFormat=pf24bit;
    for(int i=0;i<tBitmap->Height;++i)
    {
    ptr=(Byte *)tBitmap->ScanLine[i];
    for(int j=0;j<tBitmap->Width;++j)
    {
    x=float(ptr[j*3]);
    y=float(ptr[j*3+1]);
    z=float(ptr[j*3+2]);
    rgbtohls(&x,&y,&z);
    delete tBitmap;
    }
    void __fastcall TForm1::rgbtohls(float *r,float *g,float *b)
    {
    float m,n,p,q,x,y,delta,h1,l1,s1;
    *r=(1.0/256)*(*r);
    *g=(1.0/256)*(*g);
    *b=(1.0/256)*(*b);
    x=max(*r,*g);
    y=max(*g,*b);
    m=max(x,y);
    p=min(*r,*g);
    q=min(*g,*b);
    n=min(p,q);
    l1=(m+n)/2;
    if (m==n)
       {s1=0;h1=0;}
    else
       {if (l1<=0.5)
           s1=(m-n)/(m+n);
       else
           s1=(m-n)/(2-m-n);
       delta=m-n;
       if (*r==m)
           h1=(*g-*b)/delta;
       else if (*g==m)
           h1=2+(*b-*r)/delta;
       else if (*b==m)
            h1=4+(*r-*g)/delta;
        h1=h1/6;
       if (h1<0)
        h1=h1+1;
        }*r=360*h1;
    *g=360*l1;
    *b=360*s1;
    }
      

  3.   

    谢谢weibz0525(小虫)老兄; 
       能不能把一个点的 color(24位) 拆分为ESL的格式的算法简单的介绍一下啊,谢谢啦!
      

  4.   

    具体这个算法是怎么实现的我也说不清楚,得找个图形处理毕业的研究生给你讲讲。
    这个用到的是球体变换,还有其他几种变换。
    知道这样写就可以了,真想know how ,那里边有许多复杂的数学推导呢。
      

  5.   

    // Bitmap.ScanLine[X] 可以获取图像象素的内存地址,24Bits的Bitmap的每一象
    // 素是以三原色RGB的次序存放的,改变RGB的值就可调节Bitmap的色彩.
    // R, G, B: -255~255
    procedure RGB(var Bmp: TBitmap; R, G, B: Integer);
    var
      X, Y: Integer;
      I: Byte;
      ColorTable: array[0..255] of TRGBColor;
      pRGB: PRGBColor;
    begin
      for I := 0 to 255 do
      begin
        ColorTable[I].R := Byte(I + R);
        ColorTable[I].G := Byte(I + G);
        ColorTable[I].B := Byte(I + B);
      end;  for Y := 0 to Bmp.Height - 1 do
      begin
        pRGB := Bmp.ScanLine[Y];
        for X := 0 to Bmp.Width - 1 do
        begin
          pRGB.R := ColorTable[pRGB.R].R;
          pRGB.G := ColorTable[pRGB.G].G;
          pRGB.B := ColorTable[pRGB.B].B;
        end;
        Inc(pRGB);
      end;
    end;// 改变图像的亮度,也只需调用RGB(Bmp, X, X, X)改变三原色.
    // 调节Bitmap的对比度
    // 应用公式: 新颜色值 = (旧颜色值 - 128) * 系数 + 128
    procedure Contrast(var Bmp: TBitmap; Amount: Integer);
    // Amount: -255~255
    var
      X, Y: Integer;
      I: Byte;
      ColorTable: array[0..255] of TRGBColor;
      pRGB: PRGBColor;
    begin
      for I := 0 to 126 do
      begin                          
        Y := (Abs(128 - I) * Amount) div 256;
        ColorTable[I].r := GetRValue(Byte(I - Y));
        ColorTable[I].g := GetGValue(Byte(I - Y));
        ColorTable[I].b := GetBValue(Byte(I - Y));
      end;
      for I := 127 to 255 do
      begin
        Y := (Abs(128 - I) * Amount) div 256;
        ColorTable[I].r := GetRValue(Byte(I + Y));
        ColorTable[I].g := GetGValue(Byte(I + Y));
        ColorTable[I].b := GetBValue(Byte(I + Y));
      end;
      for Y := 0 to Bmp.Height - 1 do
      begin
        pRGB := Bmp.ScanLine[Y];
        for X := 0 to Bmp.Width - 1 do
        begin
          pRGB.R := ColorTable[pRGB.R].R;
          pRGB.G := ColorTable[pRGB.G].G;    
          pRGB.B := ColorTable[pRGB.B].B;
          Inc(pRGB);
        end;
      end;
    end;// 改变饱和度
    procedure Saturation(var Bmp: TBitmap; Amount: Integer); // Amount: 0~510
    var
      Grays: array[0..767] of Integer;
      Alpha: array[0..255] of Word;
      Gray, X, Y: Integer;
      pRGB: PRGBColor;
      I: Byte;
    begin
      for I := 0 to 255 do Alpha[I] := (I * Amount) shr 8;
      x := 0;
      for I := 0 to 255 do 
      begin
        Gray := I - Alpha[I];
        Grays[X] := Gray; Inc(X);
        Grays[X] := Gray; Inc(X);  
        Grays[X] := Gray; Inc(X);
      end;
      for Y := 0 to Bmp.Height - 1 do
      begin
        pRGB := Bmp.ScanLine[Y];
        for X := 0 to Bmp.Width - 1 do
        begin
          Gray := Grays[pRGB.R + pRGB.G + pRGB.B];
          pRGB.R := Byte(Gray + Alpha[pRGB.R]);
          pRGB.G := Byte(Gray + Alpha[pRGB.G]);
          pRGB.B := Byte(Gray + Alpha[pRGB.B]);
          Inc(pRGB);
        end;
      end;
    end;//对于Jpg的处理,与Bitmap类似,因为TJpegImage内部有TBitmap.//Bmp := TBitmap.Create;
    //Bmp.Assign(Jpg);procedure TForm1.FormCreate(Sender: TObject);
    begin
      bmp := TBitmap.Create;
      bmp.Assign(image1.Picture.Graphic);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      RGB(Bmp, StrToInt(edit1.text),StrToInt(edit2.text),StrToInt(edit3.text));
      image1.Picture.Graphic.Assign(bmp);
      image1.Refresh;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      Contrast(Bmp, strtoint(edit1.text));
      image1.Picture.Graphic.Assign(bmp);
      image1.Refresh;
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
      Saturation(Bmp, strtoint(edit1.text));
      image1.Picture.Graphic.Assign(bmp);
      image1.Refresh;
    end;