Page 1 of 1

-distort Affine

Posted: 2013-04-04T13:50:08-07:00
by abjones
using Windows 2003 Server
ActivePerl-5.16.3.1603-MSWin32-x86-296746.msi
ImageMagick-6.8.4-4-Q8-x86-dll.exe (btw I cannot get PerlMagick from ImageMagick-6.8.4-5-Q8-x86-dll.exe or ImageMagick-6.8.4-6-Q8-x86-dll.exe to work with my Windows 2003 Server )

after I construct an image and write it to disk,
I can run from command line:

Code: Select all

convert d:/temp/after.gif -virtual-pixel white -distort Affine "0,1,0,0,255,254,255,255" d:/temp/distort.png
and get a useful result image; but continuing in perl

Code: Select all

#perl
use Image::Magick;


	my $image=Image::Magick->new;
	my $error = '';

	$error = $image->ReadImage('d:/temp/after.gif');  die "ImageMagick error $error" if $error;


	$error = $image->Distort('virtual-pixel'=>"white", type=>"Affine",

		points=>[0,1,0,0, 255,254,255,255] );

	die "ImageMagick Distort error $error" if $error;


	my $type='png';
	$error = $image->Set(magick=>"$type");	die "ImageMagick error $error" if $error;
	$image->Write('d:/temp/distort.png');	die "ImageMagick error $error" if $error;
i get
ImageMagick Distort error Exception 400: memory allocation failed GenerateCoefficients @ error/distort.c/GenerateCoefficients/506 at testDistort.txt line 15.
Any help is greatly appreciated.
A B Jones

Re: -distort Affine

Posted: 2013-04-04T14:49:35-07:00
by fmw42
Your control points appear to be nearly an identity transform (no change). Not sure why you are doing that unless just testing.

My guess is that PerlMagick may still be using the old syntax for the control points. Try changing your control points to the older format. see http://www.imagemagick.org/Usage/distor ... rol_points

Re: -distort Affine

Posted: 2013-04-05T06:05:49-07:00
by abjones
OK, call me dense, but I can find no perl examples on that page that help me understand how to express control points in my program. Can you please post my code "corrected"? Thanks and good health!

Re: -distort Affine

Posted: 2013-04-05T08:59:46-07:00
by fmw42
It is in the warning comment. In the new format one alternates input and output coordinates. In the old format one specifies all the input coords first and then all the output coords.

"Before IM version 6.3.6-0 when the Distort Operator operator was first introduced, the coordinate ordering for control points was defined as all the source coordinates, followed by all the destination coordinates. This however made it very hard to determine which source and destination coordinates corresponded to each other, and did not allow for the simple appending of more control points to further refine a distortion."


convert d:/temp/after.gif -virtual-pixel white -distort Affine "0,1,0,0,255,254,255,255" d:/temp/distort.png

was in old syntax

convert d:/temp/after.gif -virtual-pixel white -distort Affine "0,1 255,254 0,0 255,255" d:/temp/distort.png

However, I would really be surprised if this is the issue.

Re: -distort Affine

Posted: 2013-04-07T06:02:06-07:00
by abjones
I have no problem running a command line Distort Affine. My problem is with Perl. I re-wrote my example to use generic image; Please, can someone "fix" it for me :

Code: Select all

#perl
use strict;
use Image::Magick;


	my $image=Image::Magick->new;
	my $error = '';

	$error=$image->Set(size=>'256x256');	die "ImageMagick Set error $error" if $error;
	$error=$image->ReadImage('xc:blue');	die "ImageMagick ReadImage error $error" if $error;

	$error= $image->Draw(primitive=>'line', stroke=>'red', fill=>'none',
		points=>"0 0 255 255",strokewidth=>2);
	die "ImageMagick Draw error $error" if $error;


	$error = $image->Distort('virtual-pixel'=>"white", type=>"Affine",
		points=>[1, 0, 0, 0, 255, 254, 255, 255] );

	die "ImageMagick Distort error $error" if $error;

	my $type='png';
	$error = $image->Set(magick=>'png');	die "ImageMagick Set error $error" if $error;
	my @blob = $image->ImageToBlob();

	print @blob;

Re: -distort Affine

Posted: 2013-04-10T12:13:17-07:00
by abjones
I found an old forum entry:
Re: PerlMagick distort() syntax

Postby magick ยป 2008-04-12T18:05:52+00:00
This works for us (we're using ImageMagbick 6.4.0-7):

$image->Distort('virtual-pixel'=>"transparent", type=>"Perspective", points=>[0,0,25,25,0,90,0,90,90,0,70,25,90,90,90,65]);
so I cut and paste into my perl program

Code: Select all

my $error = $image->Distort('virtual-pixel'=>"transparent", type=>"Perspective", points=>[0,0,25,25,0,90,0,90,90,0,70,25,90,90,90,65]);
die "ImageMagick Distort error $error" if $error;
and get
ImageMagick Distort error Exception 400: memory allocation failed GenerateCoefficients @ error/distort.c/GenerateCoefficients/506