Page 1 of 1

distorted image

Posted: 2009-08-13T05:40:21-07:00
by bjojon
Hi,

I am trying to to make a slightly distorted scanned image to fit a square. I have found the 'distort' command in the help file which looked promizing.

My bit map (tiff-file) is 5905x5902 in size. The corners of the actual picture is
0, 0
0, 5902
5905, 0
5901, 5902
after skewing and cropping the original scanned image.
I now try to transform the image to a 5900x5900 square using the command

c:\>convert Ina0882_24bit.tif -virtual-pixel white -distort Perspective '0,0,0,0,0,5902,0,5900,5905,0,5900,0,5901,5902,5900,5900' Ina0882_24bit_final.tif

Unfortunately I get the following error message which does not say much to me
convert: invalid argument for option Affine : 'require at least 1 CPs' @ distort
.c/GenerateCoefficients/449.

an output image is produced which is some 30% larger than the original, but pixel dimensions are the same and the image corners are at the original coordinates.

I use
Version: ImageMagick 6.5.4-10 2009-08-08 Q16 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
on a Windows XP SP3 box

Anyone can help?

best regards
/bjojon

Re: distorted image

Posted: 2009-08-13T09:09:14-07:00
by fmw42
after skewing and cropping the original scanned image.
I now try to transform the image to a 5900x5900 square using the command
What do you mean by "after skewing and cropping"? If you have already done that then why do you need the following?
c:\>convert Ina0882_24bit.tif -virtual-pixel white -distort Perspective '0,0,0,0,0,5902,0,5900,5905,0,5900,0,5901,5902,5900,5900' Ina0882_24bit_final.tif
Try spacing out the coord pairs without the extra commas and see if that helps. In principal it should not matter.
e.g

'0,0 0,0 0,5902 0,5900 5905,0 5900,0 5901,5902 5900,5900'

With such little change in the perspective, you may be too close to an affine and the denominator may be going awry.

You could also try just -affine -transform

see http://www.imagemagick.org/Usage/distor ... ne/#affine

Re: distorted image

Posted: 2009-08-13T22:35:36-07:00
by bjojon
Hi fmw42,
and thanks for the suggestion. I tried to separate coordinates with spaces as you suggested, unfortunately situation got worse. Convert now tried to interpret the coordinate pairs after each space as a file name.
It seams as a parsing error.

After some testing I found that the following syntax is accepted.

Code: Select all

convert src.tif -virtual-pixel white -distort Perspective 182,178,182,178,165,6080,182,6083,6086,188,6087,178,6072,6081,6087,6083 out.tif
i.e. no spaces among coordinates and no quote-marks ?

BTW, I restarted from the original source bitmap to make all conversions in one blow, therefore coordinate numbers are different.

Thanks alot, my problem is solved
/bjojon

Re: distorted image

Posted: 2009-08-13T22:42:46-07:00
by anthony
fmw42 wrote:Try spacing out the coord pairs without the extra commas and see if that helps. In principal it should not matter.
e.g

'0,0 0,0 0,5902 0,5900 5905,0 5900,0 5901,5902 5900,5900'

With such little change in the perspective, you may be too close to an affine and the denominator may be going awry.
Spacing out the arguments will help you group them better so you can see the pairs of x,y coodinates. Makes sure you got them all.

For near unity adjustments like this the denominator is almost 1.0. It is only at the horizon for perspective distortions that you get things going bad in that way. As such that is now a problem.

The error message however means it didn't fine any coordinates at all. Could you have some unusual characters in the string? maybe you spaces are meta-spaces that some editors like to insert? Watch out for close looking UTF characters.

Re: distorted image

Posted: 2009-08-14T08:01:18-07:00
by fmw42
bjojon wrote:Hi fmw42,

After some testing I found that the following syntax is accepted.

Code: Select all

convert src.tif -virtual-pixel white -distort Perspective 182,178,182,178,165,6080,182,6083,6086,188,6087,178,6072,6081,6087,6083 out.tif
i.e. no spaces among coordinates and no quote-marks ?
/bjojon

I would really suggest you space out the coordinates AND put quotes around them. Without quotes you cannot space them out.