//Call
double lut_trans [256];
double ang_rad1 = 0.0;
int ang_deg1 = 45;
double ang_rad2 = 0.0;
int ang_deg2 = 70;
double ang_rad3 = 0.0;
int ang_deg3 = 20;
int step1 = 50;
int step2 = 90;
int step3 = 255;
ang_rad1 = (PI * ang_deg1) /180;
ang_rad2 = (PI * ang_deg2) /180;
ang_rad3 = (PI * ang_deg3) /180;
create_lut(ang_rad1, lut_trans );
for(i=0; i<256; i++)
printf("[%d]=%f\n", i, lut_trans[i]);
//Implementation
long create_lut (double contrast, double* Contrast_transform )
{
long err =0;
//CONTRAST SLOPE
for(int i=0;i<256;i++){
if(i<(int)(128.0f+128.0f*tan(contrast))&&i>(int)(128.0f-128.0f*tan(contrast)))
Contrast_transform[i]=(i-128)/tan(contrast)+128;
else if(i>=(int)(128.0f+128.0f*tan(contrast)))
Contrast_transform[i]=255;
else
Contrast_transform[i]=0;
}
return err;
}
//output
[0]=0.000000
[1]=1.000000
[2]=2.000000
[3]=3.000000
[4]=4.000000
...
[137]=137.000000
..
[253]=253.000000
[254]=254.000000
[255]=255.000000
///////////////////////////////////////////
New Code
//Call
create_3levels_lut(step1,ang_rad1,step2,ang_rad2,step3,ang_rad3,lut_trans);
//Implementation
long create_3levels_lut (int step1, double contrast1,int step2, double contrast2,int step3, double contrast3, double* Contrast_transform )
{
long err =0;
for(int i=0;i<256;i++){
if(i<(int)(step1*tan(contrast1))&&i>(int)(0*tan(contrast1)))
Contrast_transform[i]=(i-step1)/tan(contrast1)+step1;
else if(i<(int)(step2*tan(contrast2))&&i>(int)(step1*tan(contrast1)))
Contrast_transform[i]=(i-step2)/tan(contrast2)+step2;
else if(i<(int)(step3*tan(contrast3))&&i>(int)(step2*tan(contrast2)))
Contrast_transform[i]=(i-step2)/tan(contrast2)+step2;
else if(i>=(int)(step3*tan(contrast3)))
Contrast_transform[i]=255;
else
Contrast_transform[i]=0;
}
return err;
}
//output
[0]=0.000000
[1]=1.000000
[2]=2.000000
[3]=3.000000
[4]=4.000000
[5]=5.000000
[6]=6.000000
[7]=7.000000
[8]=8.000000
[9]=9.000000
[10]=10.000000
[11]=11.000000
[12]=12.000000
[13]=13.000000
[14]=14.000000
[15]=15.000000
[16]=16.000000
[17]=17.000000
[18]=18.000000
[19]=19.000000
[20]=20.000000
[21]=21.000000
[22]=22.000000
[23]=23.000000
[24]=24.000000
[25]=25.000000
[26]=26.000000
[27]=27.000000
[28]=28.000000
[29]=29.000000
[30]=30.000000
[31]=31.000000
[32]=32.000000
[33]=33.000000
[34]=34.000000
[35]=35.000000
[36]=36.000000
[37]=37.000000
[38]=38.000000
[39]=39.000000
[40]=40.000000
[41]=41.000000
[42]=42.000000
[43]=43.000000
[44]=44.000000
[45]=45.000000
[46]=46.000000
[47]=47.000000
[48]=48.000000
[49]=0.000000
[50]=75.441191
[51]=75.805161
[52]=76.169131
[53]=76.533101
[54]=76.897072
[55]=77.261042
[56]=77.625012
[57]=77.988982
[58]=78.352952
[59]=78.716923
[60]=79.080893
[61]=79.444863
[62]=79.808833
[63]=80.172804
[64]=80.536774
[65]=80.900744
[66]=81.264714
[67]=81.628685
[68]=81.992655
[69]=82.356625
[70]=82.720595
[71]=83.084566
[72]=83.448536
[73]=83.812506
[74]=84.176476
[75]=84.540446
[76]=84.904417
[77]=85.268387
[78]=85.632357
[79]=85.996327
[80]=86.360298
[81]=86.724268
[82]=87.088238
[83]=87.452208
[84]=87.816179
[85]=88.180149
[86]=88.544119
[87]=88.908089
[88]=89.272060
[89]=89.636030
[90]=90.000000
[91]=90.363970
[92]=90.727940
[93]=91.091911
[94]=91.455881
[95]=91.819851
[96]=92.183821
[97]=92.547792
[98]=92.911762
[99]=93.275732
[100]=93.639702
[101]=94.003673
[102]=94.367643
[103]=94.731613
[104]=95.095583
[105]=95.459554
[106]=95.823524
[107]=96.187494
[108]=96.551464
[109]=96.915434
[110]=97.279405
[111]=97.643375
[112]=98.007345
[113]=98.371315
[114]=98.735286
[115]=99.099256
[116]=99.463226
[117]=99.827196
[118]=100.191167
[119]=100.555137
[120]=100.919107
[121]=101.283077
[122]=101.647048
[123]=102.011018
[124]=102.374988
[125]=102.738958
[126]=103.102928
[127]=103.466899
[128]=103.830869
[129]=104.194839
[130]=104.558809
[131]=104.922780
[132]=105.286750
[133]=105.650720
[134]=106.014690
[135]=106.378661
[136]=106.742631
[137]=107.106601
[138]=107.470571
[139]=107.834542
[140]=108.198512
[141]=108.562482
[142]=108.926452
[143]=109.290422
[144]=109.654393
[145]=110.018363
[146]=110.382333
[147]=110.746303
[148]=111.110274
[149]=111.474244
[150]=111.838214
[151]=112.202184
[152]=112.566155
[153]=112.930125
[154]=113.294095
[155]=113.658065
[156]=114.022036
[157]=114.386006
[158]=114.749976
[159]=115.113946
[160]=115.477917
[161]=115.841887
[162]=116.205857
[163]=116.569827
[164]=116.933797
[165]=117.297768
[166]=117.661738
[167]=118.025708
[168]=118.389678
[169]=118.753649
[170]=119.117619
[171]=119.481589
[172]=119.845559
[173]=120.209530
[174]=120.573500
[175]=120.937470
[176]=121.301440
[177]=121.665411
[178]=122.029381
[179]=122.393351
[180]=122.757321
[181]=123.121291
[182]=123.485262
[183]=123.849232
[184]=124.213202
[185]=124.577172
[186]=124.941143
[187]=125.305113
[188]=125.669083
[189]=126.033053
[190]=126.397024
[191]=126.760994
[192]=127.124964
[193]=127.488934
[194]=127.852905
[195]=128.216875
[196]=128.580845
[197]=128.944815
[198]=129.308785
[199]=129.672756
[200]=130.036726
[201]=130.400696
[202]=130.764666
[203]=131.128637
[204]=131.492607
[205]=131.856577
[206]=132.220547
[207]=132.584518
[208]=132.948488
[209]=133.312458
[210]=133.676428
[211]=134.040399
[212]=134.404369
[213]=134.768339
[214]=135.132309
[215]=135.496279
[216]=135.860250
[217]=136.224220
[218]=136.588190
[219]=136.952160
[220]=137.316131
[221]=137.680101
[222]=138.044071
[223]=138.408041
[224]=138.772012
[225]=139.135982
[226]=139.499952
[227]=139.863922
[228]=140.227893
[229]=140.591863
[230]=140.955833
[231]=141.319803
[232]=141.683773
[233]=142.047744
[234]=142.411714
[235]=142.775684
[236]=143.139654
[237]=143.503625
[238]=143.867595
[239]=144.231565
[240]=144.595535
[241]=144.959506
[242]=145.323476
[243]=145.687446
[244]=146.051416
[245]=146.415387
[246]=146.779357
[247]=255.000000
[248]=255.000000
[249]=255.000000
[250]=255.000000
[251]=255.000000
[252]=255.000000
[253]=255.000000
[254]=255.000000
[255]=255.000000
|