Page 1 of 1

Adjusting color with raito and offset [Optimization Needed]

Posted: 2010-03-16T03:13:57-07:00
by ivanw
I am totally new to imagick. Please help me this simple task which I just don't know how it works.

I have images RGB-adjusted by my user's flash tool .

The formula looks like this

R_new = R_old * R_raido + R_offset
G_new = G_old * G_raido + G_offset
B_new = B_old * B_raido + B_offset

The values that I have are the _ratio and _offset for each RGB.
(the _ratio and _offset will apply to each pixel of the old image)
* _ratios are range from 100% to -100%
* _offset are range from -255 to 255

Now I only have the old image with these adjustment factors.
How I can reproduce the new image using Imgick functions ?

I went through the the image documents, and I am totally lost of how imagick works.
it will be nice if someone can show me a sample Imagick funciton and how to pass it's parameters.
==============================================================================================
Thanks for hints. I end up doing it this way, and the result is correct now.

Can someone tell me if there is a way to do it more efficiently?
Is it possible to merge the 4 converts into 1 convert command and optimize the speed?

I have lots of images need to be processed.

==============================================================================================
hair.png, shoes.png and body.png are from the old images. the RGB ratio and offset are different for every images
==============================================================================================
convert hair.png -channel red -fx "u.r*0.8" -channel green -fx "u.g*0.7+(-20/256)" -channel blue -fx "u.b*0.6+(10/256)" hair_final.png
convert shoes.png -channel red -fx "u.r*0.75" -channel green -fx "u.g*0.5+(-30/256)" -channel blue -fx "u.b*0.9+(200/256)" shoes_final.png
convert body.png -channel red -fx "u.r*0.57" -channel green -fx "u.g*0.81" -channel blue -fx "u.b*0.4" body_final.png
convert body_final.png -compose over hair_final.png -composite -compose over shoes_final.png -composite final.jpg


Thanks a lot

Re: Adjusting image color with raito and offset

Posted: 2010-03-16T09:21:18-07:00
by fmw42
Don't know Imagick, but in command line, see the following functions:

-cdl --- http://www.imagemagick.org/script/comma ... ns.php#cdl

-function polynomial --- http://www.imagemagick.org/script/comma ... p#function

Re: Adjusting image color with raito and offset

Posted: 2010-03-16T10:38:36-07:00
by Bonzo
With Imagick you have to use the operators that somebody has decided to get from ImageMagick. If you use ImageMagick using exec() you can use all the operators available. BUT safe mode must be turned off and I think you need php installed as fcgi.

Re: Adjusting image color with raito and offset

Posted: 2010-03-16T23:41:08-07:00
by ivanw
Thanks for hints, I end up doing it this way, and the result is correct now.

Can someone tell me if there is a way to do it more efficiently?
Is it possible to merge the 4 converts into 1 convert command and optimize the speed?

I have lots of images need to be processed.

==============================================================================================
hair.png, shoes.png and body.png are from the old images. the RGB ratio and offset are different for every images
==============================================================================================
convert hair.png -channel red -fx "u.r*0.8" -channel green -fx "u.g*0.7+(-20/256)" -channel blue -fx "u.b*0.6+(10/256)" hair_final.png
convert shoes.png -channel red -fx "u.r*0.75" -channel green -fx "u.g*0.5+(-30/256)" -channel blue -fx "u.b*0.9+(200/256)" shoes_final.png
convert body.png -channel red -fx "u.r*0.57" -channel green -fx "u.g*0.81" -channel blue -fx "u.b*0.4" body_final.png
convert body_final.png -compose over hair_final.png -composite -compose over shoes_final.png -composite final.jpg


Thanks a lot