Polynomial Curves Incorrect Results ?
Posted: 2012-07-06T05:36:07-07:00
Hello all,
I'm working on a project and decided to explore ImageMagick library as all the alternatives I'm familiar with seem to be not efficient enough to perform tasks required by this project. ImageMagick command line so far seems to be fastest option however I'm having a problem with applying curves to RGB channels.
I've downloaded the im_fx_curves perl script to generate a,b,c..n factors but it seems to be giving incorrect results:
gives (1):
Now if I use this function with X-coords as input to verify Y-coords I'm getting:
(i've rounded all the numbers up to the nearest integer)
I didn't investigate im_fx_curves code so I assume there is an issue with it or Math::Polynomial lib
I have created a function that finds a,b,c...n factors using "polynomial least squares fittings" that for the same input points returns (2):
As you can see the values are pretty similar - just the dots are in different positions
When I apply my generated function to an image I get very similar results to what I get in Photoshop CS5 curves adjustment tool for R, G, B or RGB channels. The result when using -function Polynomial with im_fx_curves factors is very different. My code is as below:
that is triggered via PHP exec(), not directly from a command line but that shouldn't make any different.
Applying factors from (2) results in black image and I believe that is because IM rounds up all the values to 3 decimals.
Can you please advise why am I getting so different results - am I missing something ?
Thanks
I'm working on a project and decided to explore ImageMagick library as all the alternatives I'm familiar with seem to be not efficient enough to perform tasks required by this project. ImageMagick command line so far seems to be fastest option however I'm having a problem with applying curves to RGB channels.
I've downloaded the im_fx_curves perl script to generate a,b,c..n factors but it seems to be giving incorrect results:
Code: Select all
perl im_fx_curves.pl -p 0,0 62,45 128,127 204,187 255,255
Code: Select all
0.291*u^4 - 1.500*u^3 + 2.434*u^2 - 0.276*u
Code: Select all
0,0 62,3951761 128,75008833 204,491347155 255,1205707069
I didn't investigate im_fx_curves code so I assume there is an issue with it or Math::Polynomial lib
I have created a function that finds a,b,c...n factors using "polynomial least squares fittings" that for the same input points returns (2):
Code: Select all
0.000000290732318603847*u^4 - 0.00014996946075633902*u^3 + 0.02434208901325919*u^2 - 0.2762101120900123*u - 0.0000000000001016845989170083
When I apply my generated function to an image I get very similar results to what I get in Photoshop CS5 curves adjustment tool for R, G, B or RGB channels. The result when using -function Polynomial with im_fx_curves factors is very different. My code is as below:
Code: Select all
$cmd= "convert $in -fx '0.291*u^4 - 1.500*u^3 + 2.434*u^2 - 0.276*u' $out";
or
$cmd= "convert $in -function Polynomial '0.291,-1.500,2.434,-0.276,0' $out";
Applying factors from (2) results in black image and I believe that is because IM rounds up all the values to 3 decimals.
Can you please advise why am I getting so different results - am I missing something ?
Thanks