POV-Ray : Newsgroups : povray.binaries.images : texture interpolation... why rgb ? Server Time
2 Aug 2024 08:18:48 EDT (-0400)
  texture interpolation... why rgb ? (Message 16 to 25 of 25)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: scott
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 04:32:24
Message: <474fd8a8$1@news.povray.org>
>> Oh I knocked up a quick program to interpolate between two colours in
>> RGB space and Yuv space.  In each pair, the top version is RGB, the
>> lower version is Yuv.
>
>  The yuv interpolation doesn't look half-bad.

I realised an improvement though.

Although the "colour" part (u and v) is supposed to be interpolated evenly, 
the Y part will not be.  Y is linear luminance, ie not gamma corrected, so 
interpolating it directly will not give a very "even" looking result (there 
will be too much "white").

So I modified the code to do this (now a black-white gradient looks 
identical in both RGB and Yuv interpolation) and it looks a bit better, 
especially when going from dark to light colours.  Again, top bar is RGB and 
lower bar is Yuv.

Also, the problem with converting from RGB to Yuv and back is that it 
assumes your display device is exactly calibrated to a standard (I used sRGB 
in the calculations).  If it's not then the results won't look as good as 
they could.


Post a reply to this message


Attachments:
Download 'interpolation comparison 2.png' (3 KB)

Preview of image 'interpolation comparison 2.png'
interpolation comparison 2.png


 

From: Trevor G Quayle
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 08:55:03
Message: <web.4750160f2088bdecc150d4c10@news.povray.org>
"scott" <sco### [at] laptopcom> wrote:
> >> Oh I knocked up a quick program to interpolate between two colours in
> >> RGB space and Yuv space.  In each pair, the top version is RGB, the
> >> lower version is Yuv.
> >
> >  The yuv interpolation doesn't look half-bad.
>
> I realised an improvement though.
>
> Although the "colour" part (u and v) is supposed to be interpolated evenly,
> the Y part will not be.  Y is linear luminance, ie not gamma corrected, so
> interpolating it directly will not give a very "even" looking result (there
> will be too much "white").
>
> So I modified the code to do this (now a black-white gradient looks
> identical in both RGB and Yuv interpolation) and it looks a bit better,
> especially when going from dark to light colours.  Again, top bar is RGB and
> lower bar is Yuv.
>
> Also, the problem with converting from RGB to Yuv and back is that it
> assumes your display device is exactly calibrated to a standard (I used sRGB
> in the calculations).  If it's not then the results won't look as good as
> they could.

I think this does present an interesting result.  Similar to the RGB gradient,
the colour luminance is constantly increasing or decreasing (unlike in HSV or
HSL where it tends to arc up or down past the final luminance and back again),
however following a different path of colour mix.

-tgq


Post a reply to this message

From: Trevor G Quayle
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 09:00:01
Message: <web.4750173f2088bdecc150d4c10@news.povray.org>
Having seen the differences between the different colour spaces, I think rather
than trying to figure out which is right or wrong (as opinion on this can vary
drastically)  I think it could be of use to be able to implement this in future
POV versions (likely POV4) provided efficient conversion algorithms can be made
(my HSL/HSV algorithm is SDL function based and renders quite slow compared to
the regular RGB gradient).  Anywhere a pattern gradient can be applied, be able
to specify the colour space to use (RGB being default) and have whatever colour
spaces can be properly set up (HSV,HSL,YUV, etc.)

-tgq


Post a reply to this message

From: scott
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 09:49:24
Message: <475022f4$1@news.povray.org>
Yes, the "brightness" will ramp up or down linearly in gamma-corrected 
space.

The colour will linearly interpolate between two points in the uv plane.

You can see a picture of the uv plane here:

http://content.answers.com/main/content/img/CDE/_CIE1976.JPG

The outer edge are single-wavelength colours, with the wavelengths marked 
on.  If you mix two or more wavelengths you can simply take a weighted 
average of the uv coordinates and that will give you the resulting colour. 
That is essentially what I am doing in my code, varying the % of each colour 
linearly from 0-100%.

The problem occurs when you interpolate from blue to yellow (or any other 
pair either side of white).  In real life, if you mix 50% blue and 50% 
yellow you do get white (it's how most white LEDs work).

To me though it doesn't seem right that if you want a nice colour gradient 
between a strong blue and yellow, you end up with a muddy grey in the 
middle, but then I don't know what else you could do without introducing 
other colours...


Post a reply to this message

From: scott
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 09:57:58
Message: <475024f6$1@news.povray.org>
>> I'm talking about
>> the CIE Yuv color space, revised in 1976 so that colours are spread
>> equally in the uv plane.  See:
>
> I give up on the evaluation of the spectrum... as for all CIELab,
> L*a*b* and such... it's far too much complex and removed from my
> skill with computer.
> Converting formulaes which request the performance of integration is
> a bit too much.

You actually don't need to do anything with the spectrum.  You just need to 
choose a physical colour-space to work in (sRGB or AdobeRGB are common), and 
then a 3x3 matrix is available to convert from linear RGB values to XYZ. 
Once you have the XYZ colour then it's just a simple formula to convert to 
Yuv.

Of course you can derive the 3x3 matrix from first principles using the 
primary colours' spectrums and viewer functions, but that usually isn't 
necessary.


Post a reply to this message

From: Le Forgeron
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 12:08:01
Message: <47504371$1@news.povray.org>
Le 30.11.2007 14:59, Trevor G Quayle nous fit lire :
> Having seen the differences between the different colour spaces, I think rather
> than trying to figure out which is right or wrong (as opinion on this can vary
> drastically)  I think it could be of use to be able to implement this in future
> POV versions (likely POV4) provided efficient conversion algorithms can be made
> (my HSL/HSV algorithm is SDL function based and renders quite slow compared to
> the regular RGB gradient).  Anywhere a pattern gradient can be applied, be able
> to specify the colour space to use (RGB being default) and have whatever colour
> spaces can be properly set up (HSV,HSL,YUV, etc.)

I would agree... would you mind sharing your SDL interpolation code ?
-- 
The superior man understands what is right;
the inferior man understands what will sell.
-- Confucius


Post a reply to this message

From: Trevor G Quayle
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 12:45:00
Message: <web.47504bf52088bdecc150d4c10@news.povray.org>
Le Forgeron <jgr### [at] freefr> wrote:
> I would agree... would you mind sharing your SDL interpolation code ?

I don't mind.  It can be likely far better optimized.  It is quite easy to do as
a macro using #if, #range, etc., but was quite cumbersome to make a continuous
function through creative use of select(), especially since functions don't
handle vectors, so each component has to be split out separately and
recombined.

I have also influded the function for converting HSV/HSL to XYZ and back

The formulae for these are based on the ones from wikipedia
http://en.wikipedia.org/wiki/HSV_color_space

Let me know if you see any errors or have questions.

//RGB to HSV
#declare HHSV=function(R,G,B)
{
  60*
  select(
    min(R,G,B)-max(R,G,B)
  ,//min<max
    select(
      R-max(R,G,B)
    ,//R<max
      select(
        B-max(R,G,B)
      ,//G=max
        (B-R)/(max(R,G,B)-min(R,G,B))+2
      ,//B=max
        (R-G)/(max(R,G,B)-min(R,G,B))+4
      )
    ,//R=max
      (G-B)/(max(R,G,B)-min(R,G,B))+
      select(
        G-B
      ,//G>B
        6
      ,//B>G
        0
      )
    )
  ,//min=max
    0
  )
}
#declare SHSV=function(R,G,B) {select(-max(R,G,B),1-min(R,G,B)/max(R,G,B),0)}
#declare VHSV=function(R,G,B) {max(R,G,B)}
//END RGB to HSV

//RGB to HSL
#declare HHSL=function(R,G,B) {HHSV(R,G,B)}   //same as HSV
#declare SHSL=function(R,G,B)
{
  select(
    min(R,G,B)-max(R,G,B)
  ,//max>min
    (max(R,G,B)-min(R,G,B))/
    select(
      1-(max(R,G,B)+min(R,G,B))
    ,//l>1/2
      2-(max(R,G,B)+min(R,G,B))
    ,//1/2=>l
      max(R,G,B)+min(R,G,B)
    )
  ,//max=min
    0
  )
}
#declare LHSL=function(R,G,B){(max(R,G,B)+min(R,G,B))/2}
//END RGB to HSL

//HSL to RGB
#declare tHSL=function(H,C){(H/360+C/3)-floor(H/360+C/3)}
#declare qHSL=function(H,S,L){select(L-1/2,L*(1+S),L+S-L*S)}
#declare pHSL=function(H,S,L){2*L-qHSL(H,S,L)}
#declare CHSL=function(H,S,L,C)
{
  select(
    -S
  ,//S>0
    select(
      tHSL(H,C)-1/6
    ,//tc<1/6
      pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*tHSL(H,C)
    ,
      select(
        tHSL(H,C)-1/2
      ,//tc<1/2
        qHSL(H,S,L)
      ,
        select(
          tHSL(H,C)-2/3
        ,//tc<2/3
          pHSL(H,S,L)+2*(qHSL(H,S,L)-L)*6*(2/3-tHSL(H,C))
        ,//esle
          pHSL(H,S,L)
        )
      )
    )
  ,//S=0
    L
  )
}
#declare RHSL=function (H,S,L){CHSL(H,S,L,+1)}
#declare GHSL=function (H,S,L){CHSL(H,S,L, 0)}
#declare BHSL=function (H,S,L){CHSL(H,S,L,-1)}
//END HSL to RGB




//HSV to RGB
#declare hHSV=function (H){floor(mod(H/60,6))}
#declare fHSV=function (H){H/60-hHSV(H)}
#declare pHSV=function (H,S,V){V*(1-S)}
#declare qHSV=function (H,S,V){V*(1-fHSV(H)*S)}
#declare tHSV=function (H,S,V){V*(1-(1-fHSV(H))*S)}
#declare RHSV=function (H,S,V)
{
  select(hHSV(H)-0.5
  ,//0
    V
  ,
    select(hHSV(H)-1.5
    ,//1
      qHSV(H,S,V)
    ,
      select(hHSV(H)-2.5
      ,//2
        pHSV(H,S,V)
      ,
        select(hHSV(H)-3.5
        ,//3
          pHSV(H,S,V)
        ,
          select(hHSV(H)-4.5
          ,//4
            tHSV(H,S,V)
          ,//5
            V
          )
        )
      )
    )
  )
}

#declare GHSV=function (H,S,V)
{
  select(hHSV(H)-0.5
  ,//0
    tHSV(H,S,V)
  ,
    select(hHSV(H)-1.5
    ,//1
      V
    ,
      select(hHSV(H)-2.5
      ,//2
        V
      ,
        select(hHSV(H)-3.5
        ,//3
          qHSV(H,S,V)
        ,//4,5
          pHSV(H,S,V)
        )
      )
    )
  )
}

#declare BHSV=function (H,S,V)
{
  select(hHSV(H)-0.5
  ,//0
    pHSV(H,S,V)
  ,
    select(hHSV(H)-1.5
    ,//1
      pHSV(H,S,V)
    ,
      select(hHSV(H)-2.5
      ,//2
        tHSV(H,S,V)
      ,
        select(hHSV(H)-3.5
        ,//3
          V
        ,
          select(hHSV(H)-4.5
          ,//4
            V
          ,//5
            qHSV(H,S,V)
          )
        )
      )
    )
  )
}
//END HSV to RGB


//CONVERT HSV to XYZ (polar to caresian) for interpolation and back
#declare HSVX=function(H,S,V){sin(radians(H))*S}
#declare HSVY=function(H,S,V){cos(radians(H))*S}
#declare HSVZ=function(H,S,V){V}
#declare
XYZH=function(X,Y,Z){select(-sqrt(X*X+Y*Y),abs(degrees(acos(Y/sqrt(X*X+Y*Y)))-select(X,360,0)),0)}
#declare XYZS=function(X,Y,Z){sqrt(X*X+Y*Y)}
#declare XYZV=function(X,Y,Z){Z}

#declare HSLX=function(H,S,L){sin(radians(H))*S}
#declare HSLY=function(H,S,L){cos(radians(H))*S}
#declare HSLZ=function(H,S,L){L}
//H & S same as above
#declare XYZL=function(X,Y,Z){Z}
//END CONVERT HSV to XYZ

#declare INTRGB=function (PTA,PTB,K){PTA+(PTB-PTA)*K}


Post a reply to this message

From: Le Forgeron
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 13:18:36
Message: <475053fc@news.povray.org>
Le 30.11.2007 18:44, Trevor G Quayle nous fit lire :

> I have also influded the function for converting HSV/HSL to XYZ and back

Thanks, that's interesting.
I trusted the povray macro for CRGB2HSV/CRGB2HSL and opposite for
HSV/L <->RGB.
XYZ opens an interesting path.

-- 
The superior man understands what is right;
the inferior man understands what will sell.
-- Confucius


Post a reply to this message

From: Trevor G Quayle
Subject: Re: texture interpolation... why rgb ?
Date: 30 Nov 2007 15:55:01
Message: <web.475077962088bdecc150d4c10@news.povray.org>
Le Forgeron <jgr### [at] freefr> wrote:
> Le 30.11.2007 18:44, Trevor G Quayle nous fit lire :
>
> > I have also influded the function for converting HSV/HSL to XYZ and back
>
> Thanks, that's interesting.
> I trusted the povray macro for CRGB2HSV/CRGB2HSL and opposite for
> HSV/L <->RGB.
> XYZ opens an interesting path.
>
> --
> The superior man understands what is right;
> the inferior man understands what will sell.
> -- Confucius

The problem with the macro is that it can't be used in a function, which is what
I wanted.

Here is the pigment declaration for an HSV gradient:


#macro PIG2(RGB1,RGB2)//HSV gradient
  #declare RA=RGB1.x;#declare GA=RGB1.y;#declare BA=RGB1.z;
  #declare RB=RGB2.x;#declare GB=RGB2.y;#declare BB=RGB2.z;
  average
  pigment_map{
    [function{
      RHSV(
        XYZH(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      ,
        XYZS(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      ,
        XYZV(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      )
    } color_map{[0 rgb 0][1 rgb <1,0,0>]}]
    [function{
      GHSV(
        XYZH(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      ,
        XYZS(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      ,
        XYZV(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      )
    } color_map{[0 rgb 0][1 rgb <0,1,0>]}]
    [function{
      BHSV(
        XYZH(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      ,
        XYZS(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      ,
        XYZV(

INTRGB(HSVX(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVX(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVY(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVY(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        ,

INTRGB(HSVZ(HHSV(RA,GA,BA),SHSV(RA,GA,BA),VHSV(RA,GA,BA)),HSVZ(HHSV(RB,GB,BB),SHSV(RB,GB,BB),VHSV(RB,GB,BB)),x)
        )
      )
    } color_map{[0 rgb 0][1 rgb <0,0,1>]}]
  }
#end

    box{<0,0,0>,<1,0,1>
      pigment{PIG2(COLA,COLB)}
      finish{ambient 3 diffuse 0}
      translate <-1/2,0,-1/2>
      scale <LEN,1,WID/3*2>
      translate z*WID/3*2
    }


Post a reply to this message

From: Le Forgeron
Subject: Re: texture interpolation... why rgb ?
Date: 5 Dec 2007 17:09:47
Message: <475721ab@news.povray.org>
here is a small experiment (real patched code), currently only for
polygon interpolation.

Still a little problem of green for degenerate hsv...

Next step, the blob 3D object...

Playing with ADC_bailout might be fun, if only it was per object and
not a global.
-- 
The superior man understands what is right;
the inferior man understands what will sell.
-- Confucius


Post a reply to this message


Attachments:
Download 'demo1.png' (87 KB) Download 'demo2.png' (72 KB) Download 'demo3.png' (72 KB) Download 'demo4.png' (98 KB) Download 'demo5.png' (86 KB)

Preview of image 'demo1.png'
demo1.png

Preview of image 'demo2.png'
demo2.png

Preview of image 'demo3.png'
demo3.png

Preview of image 'demo4.png'
demo4.png

Preview of image 'demo5.png'
demo5.png


 

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.