Hi everyone i have a question like is there any way to do Perspective distortion which resizes image? Example:
Original image size : 100x100px
Now i'd like to do Perspective distortion to get image with size 100x150px:
0,0,0,0 0,100,0,100 100,0,100,0 100,100,100,150
When i'm using points like above my image is the same as original, it is not resized and trapezoid. Is there any way to achive something like that ?
Distort Perspective
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Distort Perspective
So you are achieving the desired distortion, but you want the resulting canvas size to be larger? If I'm not understanding, images may help.
-distort keeps the same canvas size. +distort attempts to show the whole of the distorted image. Further control can be gained using -define distort:viewport={geometry_string} For further information see:
http://www.imagemagick.org/script/comma ... hp#distort
-distort keeps the same canvas size. +distort attempts to show the whole of the distorted image. Further control can be gained using -define distort:viewport={geometry_string} For further information see:
http://www.imagemagick.org/script/comma ... hp#distort
Re: Distort Perspective
witch +distort Perspective i've achived in 90% what i wanted. Output image is resized but ImageMagick adds a 2 pixel width border, so output image is 102x152px instead of 100x150. Do you know how it would be in Magick++ (C++) diffrence between -distort and +distort ?
Anyway thanks a lot
Anyway thanks a lot
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Distort Perspective
Not sure that should be, but you can try using -fuzz XX% -trim +repage to remove it. Also you might want to use image coordinates rather than pixel coordinates. See http://www.imagemagick.org/Usage/distor ... oordinatesImageMagick adds a 2 pixel width border
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Distort Perspective
I think this is likely. Try changing:fmw42 wrote:Also you might want to use image coordinates rather than pixel coordinates.
0 => 0.5
100 => 99.5
150 => 149.5
Even then, I did say "+distort attempts". If it is closer but still not perfect, you can shave another 0.05 off, or use -define distort:viewport={geometry_string} to specify the output canvas explicitly.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Distort Perspective
I would not use 'pixel centers' but edges as you did originally. Just remember the numbers are floating point, and whole numbers are the 'edges' of pixel areas (image coordinates). Pixel centers are typically only used when liniting up image according to the pixel, rather than using the edge.
See... Layering Distorted Images
http://www.imagemagick.org/Usage/layers/#layer_distort
The 2 pixel with border is to hold 'semi-transparent pixels' that often results in any re-sampled resize (scaling) of an image. Normal resize just 'clips' (actually ignores) such fine details, but distort does not. These pixels are important as they handle the 'edge joining' of multiple images, or layering of images on other images properly.
Actually the 2 pixels is actually a bit of a fudge. In reality, the number of extra pixels added should be the re-sampling filter window radius, scaled appropriately. Which for most distortions is 2*scaling factor. So in your case (50% enlargement) it really should really be 2 pixels * 1.5, or exactly 3 pixels added (exact is rare)!!!!
If you do not like the 2 pixels, just 'shave' the image! Or DIY your own 'viewport', as that is what +distort is actually calculating, using the equivalent forward mapped version of the distortion, if that is possible (not always possible). At least with the current fudge, you know exactly how many pixels needed to be shaved!
NOTE: The image location IS correct, on the virtual canvas (as a layered image). So the image is likely to have a -2-2 page offset. A -crop of that 'virtual canvas' will come out correct, but -shave will shift the image on the virtual canvas.
See... Layering Distorted Images
http://www.imagemagick.org/Usage/layers/#layer_distort
The 2 pixel with border is to hold 'semi-transparent pixels' that often results in any re-sampled resize (scaling) of an image. Normal resize just 'clips' (actually ignores) such fine details, but distort does not. These pixels are important as they handle the 'edge joining' of multiple images, or layering of images on other images properly.
Actually the 2 pixels is actually a bit of a fudge. In reality, the number of extra pixels added should be the re-sampling filter window radius, scaled appropriately. Which for most distortions is 2*scaling factor. So in your case (50% enlargement) it really should really be 2 pixels * 1.5, or exactly 3 pixels added (exact is rare)!!!!
If you do not like the 2 pixels, just 'shave' the image! Or DIY your own 'viewport', as that is what +distort is actually calculating, using the equivalent forward mapped version of the distortion, if that is possible (not always possible). At least with the current fudge, you know exactly how many pixels needed to be shaved!
NOTE: The image location IS correct, on the virtual canvas (as a layered image). So the image is likely to have a -2-2 page offset. A -crop of that 'virtual canvas' will come out correct, but -shave will shift the image on the virtual canvas.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Re: Distort Perspective
I always define the viewport explicitly, and now I know why it works. Thank you for the lesson anthony.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Distort Perspective
It is all on the IM Examples pages
http://www.imagemagick.org/Usage/distor ... rt_bestfit
Though the reason for the 2 extra pixels does seem to be missing... will correct.
http://www.imagemagick.org/Usage/distor ... rt_bestfit
Though the reason for the 2 extra pixels does seem to be missing... will correct.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/