Displacement map
Displacement map
Hello, could you tell me how to make something like this – viewtopic.php?f=1&t=16921#p62696 using imagick?
Thank you in advance)
Thank you in advance)
Re: Displacement map
My example:
It works - . But image don`t transform like this - .
Sorry for my bad english.
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 );
Sorry for my bad english.
Re: Displacement map
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
I don't really know Imagick that well, but try
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, -5, -5 );
$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, -5, -5 );
Re: Displacement map
These are the other options, they are responsible for the positioning..
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
You need to create and use the grayscale displacement map as well as the image. see viewtopic.php?f=1&t=16921#p62696But image don`t transform like this
Re: Displacement map
I use exactly a grayscale displacement map.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
$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
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;
?>
- Attachments
-
- Result
- result.png (97.76 KiB) Viewed 38434 times
-
- Displace
- displace.png (52.03 KiB) Viewed 38435 times
-
- Image
- image.jpg (34.72 KiB) Viewed 38435 times
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
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
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;
?>
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)
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
try much smaller numbers (both negative)$image->compositeImage( $displace, Imagick::COMPOSITE_DISPLACE, 14, -10 );
$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
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.
I've used your displacement map, but I added padding in the Photoshop - it completely removes the background.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Displacement map
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.
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.