LED 의 색좌표 x, y (CIE1931) 계산 알고리즘

반응형

table.h
0.02MB

계산상 필요한 table 은 위의 파일을 다운로드 받으세요

스펙트로메타를 통해 LED의 스펙트럼 데이타를 추출한 후 색좌표 상의 x,y (CIE1931)값을 계산하는 알고리즘 입니다. 

void CIE1931_Chromaticity(double* Wavelength, double* Spectrum,  int Length, double& x, double& y)
{
    double TristimulusX, TristimulusY, TristimulusZ;
    
    Tristimulus_Value(Wavelength, Spectrum, Length, TristimulusX, TristimulusY, TristimulusZ) ;

    try
    {
        x = TristimulusX / (TristimulusX + TristimulusY + TristimulusZ) ;
        y = TristimulusY / (TristimulusX + TristimulusY + TristimulusZ) ;
    }
    catch(...)
    {
        x = 0 ;
        y = 0 ;
    }
}
//---------------------------------------------------------------------------
void Tristimulus_Value(double* Wavelength, double* Spectrum, int Length, double& TristimulusX, double& TristimulusY, double& TristimulusZ)
{
    double X=0, Y=0, Z=0 ;
    double delta_wavelength = 380 ;
    int index = 0 ;
	
    for(int loop=0 ; loop<Length ; loop++)       // 380nm ~ 830nm 까지의 영역만 계산 ( 1nm 간격 )
    {
        if(Wavelength[loop] > 830) break ;
		
        if(Wavelength[loop] >= delta_wavelength)
        {
            X += (rgb_table[index].Red * Spectrum[loop]) ;
            Y += (rgb_table[index].Green * Spectrum[loop]) ;
            Z += (rgb_table[index].Blue * Spectrum[loop]) ;
			
            index ++ ;
            delta_wavelength += 1 ;    	// 1nm 증가 
        }		
    }	
	
    TristimulusX  = X * K ;
    TristimulusY  = Y * K ;
    TristimulusZ  = Z * K ;	
}
//---------------------------------------------------------------------------
반응형

댓글()

색좌표상의 x, y 값을 이용한 LED 색온도(CCT) 계산 알고리즘

반응형

table.h
0.02MB

계산상 필요한 table 은 위의 파일을 다운로드 받으세요

색좌표상의 x, y 값을 이용하여 발광빛의 색온도(Correlated Color Temperature)를 계산하는 코드 입니다.

 

double CCT(double xs, double ys)
{
    int j;
    double us,vs;
    double uj,vj,tj,di,dj,mi,mj;
    double cct ;  

    /* convert (x,y) to CIE 1960 (u,v) */
    try
    {
        us = (2*xs) / (-xs + 6*ys + 1.5);
        vs = (3*ys) / (-xs + 6*ys + 1.5);
    }
    catch(...)
    {
        us = 0 ;
        vs = 0 ;
    }

    /* search for closest isotemp lines */
    for(j=0 ; j<niso ; j++)
    {
        uj = isotempdata[j].ut ;
        vj = isotempdata[j].vt ;
         tj = isotempdata[j].tt ;
         mj = isotempdata[j].mirek ;

          try
          {
             dj = ((vs - vj) - tj * (us - uj)) / sqrt(1 + tj*tj) ; /* dj = distance from (us,vs) to this isotemp line */
          }
          catch(...)
          {
                dj = 0 ;
          }

    /* we stop when (di/dj) < 0.0, i.e. when distance changes sign, because this means we have found isotemp lines
       that "straddle" our point. */

          try
          {
                if ((j!=0) && (di/dj < 0.0))
                {
                    cct = 1000000.0 / (mi + (di / (di - dj)) * (mj - mi));
                    break;
                 }
            }
            catch(...)
            {
                cct = 0 ;
                break ;
            }

            di = dj;
            mi = mj;
        }

        if (j == niso) cct = -1 ;

        return cct ;
}
반응형

댓글()