can't find function for this

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
vonix

can't find function for this

Post by vonix »

hello! :)

i want to shift every color channel from a source image towards the color of a destination image by a specific factor (0..1), in order to make the source image look a little more like the destination image.

out = src + fac * (dest - src)

i couldn't find anything in the spare documentation and i didn't even achieve to manipulate the image manually on per pixel basis.

can someone help me please?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: can't find function for this

Post by magick »

See http://www.imagemagick.org/Usage/transform/#evaluate. Hopefully iMagick has a EvaluateImage() method.
vonix

Re: can't find function for this

Post by vonix »

it has, but only for single images
btw: what happens if i subtract white from grey (127 - 255)? are negative values just clamped? and if i multiply them (255 * 127)? are the mapped to 255*255?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: can't find function for this

Post by magick »

Yes, color components are clamped unless you use the HDRI version of ImageMagick. See http://www.imagemagick.org/script/high- ... -range.php.
vonix

Re: can't find function for this

Post by vonix »

hm, i don't think my host supports HDRI image magick and the color correction should be achievable with standard methods somehow...

all i want to do is move a green pixel slightly (30%) towards a red pixel for example, to get a red-ish green :) ... i just don't know how

corresponding to compose/#math: "add" compared to "plus" does a modulo if it would be clamp. so if it is viewed binary, it should be negative?

my idea was:
dest = dest SUBTRACT src
diff = dest MULTIPLY light gray (=30% or 0.3)
src = src ADD diff

but all i get are random colors... :?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: can't find function for this

Post by fmw42 »

have you tried the Imagick equivalent of -modulate to shift the hue?

see http://www.imagemagick.org/script/comma ... p#modulate
vonix

Re: can't find function for this

Post by vonix »

i think i haven't made it clear enough what my objective is. i just want to move every color of a source image a little more towards the color of a destination image (source and destination image have the same dimensions)
vonix

Re: can't find function for this

Post by vonix »

i implemented this in GD, however it takes about 4seconds to calculate on 1024x768. and i found that COMPOSITE_THRESHOLD provides exactly this functionality.

does anyone know how i can vary the factor for compositeImage()?

i tried setImageCompose() and setOption(), with every permutation of 'option:', 'compose', 'composite', 'compose:args', 'composite:args' and factors of 0.1, 0.5, 1, 50, 255, 500 but the factor is always 50%.


Code: Select all

$f = 0.3;

$srcImg = imagecreatefromjpeg( 'src.jpg' );

$destImg = imagecreatefromjpeg( 'dest.jpg' );

$width = imagesx( $srcImg );
$height = imagesy( $srcImg );
$outImg = imagecreatetruecolor( $width, $height );

for( $y = 0; $y < $height; $y++ )
{
	for( $x = 0; $x < $width; $x++ )
	{
		$srcRGB = imagecolorat( $srcImg, $x, $y );
		$srcR = ($srcRGB >> 16) & 0xFF; 
		$srcG = ($srcRGB >>  8) & 0xFF; 
		$srcB = ($srcRGB >>  0) & 0xFF;
		 
		$destRGB = imagecolorat( $destImg, $x, $y );
		$destR = ($destRGB >> 16) & 0xFF; 
		$destG = ($destRGB >>  8) & 0xFF; 
		$destB = ($destRGB >>  0) & 0xFF;
		
		$r = (int)($srcR + $f * ($destR - $srcR));  
		$g = (int)($srcG + $f * ($destG - $srcG));  
		$b = (int)($srcB + $f * ($destB - $srcB));
		
		$rgb = (int)(($r << 16) | ($g << 8) | $b);
		imagesetpixel( $outImg, $x, $y, $rgb);
	}
}

imagejpeg( $outImg, 'corrected.jpg' );
[/size]
Last edited by vonix on 2009-09-18T01:01:32-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: can't find function for this

Post by magick »

This is an ImageMagick forum. You'll need to find a GD forum for help with GD.
vonix

Re: can't find function for this

Post by vonix »

my actual question is IMagick related, i just wanted to show what i wanna do in GD
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: can't find function for this

Post by fmw42 »

again

have you tried the Imagick equivalent of -modulate to shift the hue?

see http://www.imagemagick.org/script/comma ... p#modulate
and http://www.imagemagick.org/Usage/color/#modulate


see modulateImage at http://us.php.net/imagick
Post Reply