Page 1 of 2
Displacement map
Posted: 2011-03-02T10:00:24-07:00
by Acrossfy
Hello, could you tell me how to make something like this –
viewtopic.php?f=1&t=16921#p62696 using imagick?
Thank you in advance)
Re: Displacement map
Posted: 2011-03-03T02:08:31-07:00
by Acrossfy
My example:
Code: Select all
$displace->adaptiveResizeImage( 100, null );
$image->adaptiveResizeImage( 100, null );
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, 0, 0 );
$shirt->compositeImage( $image, Imagick::COMPOSITE_OVER, 188, 200 );
It works -
. But image don`t transform like this -
.
Sorry for my bad english.
Re: Displacement map
Posted: 2011-03-03T05:57:02-07:00
by Acrossfy
I'm interested in this particular part of code, how to implement it in imagick syntax?
Code: Select all
convert image.jpg displace.png -alpha set -virtual-pixel transparent -compose displace -set option:compose:args -5x-5 -composite result.png
Re: Displacement map
Posted: 2011-03-03T10:15:44-07:00
by fmw42
I don't really know Imagick that well, but try
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, -5, -5 );
Re: Displacement map
Posted: 2011-03-03T10:35:04-07:00
by Acrossfy
These are the other options, they are responsible for the positioning..
Re: Displacement map
Posted: 2011-03-03T11:43:18-07:00
by fmw42
But image don`t transform like this
You need to create and use the grayscale displacement map as well as the image. see
viewtopic.php?f=1&t=16921#p62696
Re: Displacement map
Posted: 2011-03-03T13:50:11-07:00
by Acrossfy
I use exactly a grayscale displacement map.
Re: Displacement map
Posted: 2011-03-03T14:40:15-07:00
by fmw42
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, 0, 0 );
You have not specified the displacement image, nor the correct displacement values of -5, -5
see
http://us3.php.net/manual/en/function.i ... eimage.php
bool Imagick::compositeImage ( Imagick $composite_object , int $composite , int $x , int $y [, int $channel = Imagick::CHANNEL_ALL ] )
Also your x, y values should be -5, -5 not 0, 0
And I don't know what your $displace is? It does not look like the grayscale image from my example on the earlier link
$displace->adaptiveResizeImage( 100, null );
Re: Displacement map
Posted: 2011-03-04T09:07:42-07:00
by Acrossfy
Code:
Code: Select all
<?php
$image = new imagick( "image.jpg" );
$image->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$image->setImageBackgroundColor( new ImagickPixel( "none" ) );
$image->setImageFormat("png");
$displace = new imagick( "displace.png" );
$displace->setImageBackgroundColor( new ImagickPixel( "none" ) );
$displace->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$displace->setImageBackgroundColor( new ImagickPixel( "none" ) );
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, -5, -5 );
header( "Content-Type: image/png" );
echo $image;
?>
Re: Displacement map
Posted: 2011-03-04T11:08:14-07:00
by fmw42
In my example, the original image that was blurred to form the displacement image came from a section of the Tshirt and not the image that was to be distorted. The Tshirt folds and shading provided the basis for blurring to get the kind of distortion needed. You need some near white and near black regions near the edges to make them push in or out.
Try applying -auto-level to your displacement image. then try increasing or decreasing the value -5, -5 and/or reversing the signs.
Best advice. Take my images and values and see if you can reproduce the effect in iMagick.
Re: Displacement map
Posted: 2011-03-04T11:09:42-07:00
by fmw42
You also missed the point that you have to distort the image with the displacement map AND then composite the result over the background image. You have only distorted the image. You have not placed it over the background image. See all my steps at the original link.
Re: Displacement map
Posted: 2011-03-04T14:27:48-07:00
by Acrossfy
Code: Select all
<?php
$shirt = new imagick( "shirt.jpg" );
$image = new imagick( "image.png" );
$displace = new imagick( "displace.png" );
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, 14, -10 );
$shirt->compositeImage( $image, Imagick::COMPOSITE_OVER, 60, 80);
header( "Content-Type: image/jpg" );
echo $shirt;
?>
Result:
Images "image.png" and "displace.png" have a padding:
This suggests that the images need to increase the viewport,
such as here. But I do not know how to do it with Imagick.
It completely removes the background. But displace looks ugly, regardless of the values of x and y.
Also I do not know how to do autolevel for displavement image. This is not in the documentation.
Sorry for my bad Englsh again)
Re: Displacement map
Posted: 2011-03-04T17:37:11-07:00
by fmw42
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, 14, -10 );
try much smaller numbers (both negative)
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, -5, -5 );
or
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, -1, -1 );
or even smaller values if needed.
Where did you get the displacement image (from my example)?
Re: Displacement map
Posted: 2011-03-05T01:35:33-07:00
by Acrossfy
You don`t understand, I have many times tried different values, including those that you recommended. This does not affect the results.
I've used your displacement map, but I added padding in the Photoshop - it completely removes the background.
Re: Displacement map
Posted: 2011-03-05T10:23:40-07:00
by fmw42
why are you padding the displacement map? try using all my images and see if you can reproduce my results before trying your image. The displacement map needs to be the same size as the image. So you need to resize your image to the size of the displacement map.
What version of IM and what version of iMagick are you using?
Can you test in command line mode? If not try doing it in PHP with the exec function to see if you can reproduce my results. Then try to get the equivalent iMagick commands to work.