Adjusting color with raito and offset [Optimization Needed]

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
ivanw

Adjusting color with raito and offset [Optimization Needed]

Post 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
Last edited by ivanw on 2010-03-17T22:01:09-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjusting image color with raito and offset

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Adjusting image color with raito and offset

Post 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.
ivanw

Re: Adjusting image color with raito and offset

Post 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
Post Reply