can't find function for this
can't find function for this
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?
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?
Re: can't find function for this
See http://www.imagemagick.org/Usage/transform/#evaluate. Hopefully iMagick has a EvaluateImage() method.
Re: can't find function for this
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?
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?
Re: can't find function for this
Yes, color components are clamped unless you use the HDRI version of ImageMagick. See http://www.imagemagick.org/script/high- ... -range.php.
Re: can't find function for this
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...
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...
- 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
have you tried the Imagick equivalent of -modulate to shift the hue?
see http://www.imagemagick.org/script/comma ... p#modulate
see http://www.imagemagick.org/script/comma ... p#modulate
Re: can't find function for this
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)
Re: can't find function for this
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%.
[/size]
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' );
Last edited by vonix on 2009-09-18T01:01:32-07:00, edited 1 time in total.
Re: can't find function for this
This is an ImageMagick forum. You'll need to find a GD forum for help with GD.
Re: can't find function for this
my actual question is IMagick related, i just wanted to show what i wanna do in GD
- 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
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
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