distorted image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bjojon

distorted image

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: distorted image

Post 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
bjojon

Re: distorted image

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: distorted image

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: distorted image

Post 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.
Post Reply