Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Correction of Perspective Distortion
Date: Fri, 1 Feb 2008 01:50:17 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 76
Message-ID: <fnttsp$fm9$1@fred.mathworks.com>
References: <fnpft6$lod$1@fred.mathworks.com> <fnr09v$4ca$1@fred.mathworks.com> <fnrtqt$sed$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1201830617 16073 172.30.248.35 (1 Feb 2008 01:50:17 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 1 Feb 2008 01:50:17 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:448689


"OkinawaDolphin " <OkinawaDolphin@Hotmail.com> wrote in message 
<fnrtqt$sed$1@fred.mathworks.com>...
> It seems that it is the second kind of distortion. In 
> Matlab there are the functions such as maketform and 
> cp2tform for defining spatial transformations. Both affine 
> and projective transforms can be performed using these 
> functions. Parallel lines seem to converge and rectangles 
> are changed to rectangles or quadrilaterals. Therefore I 
> think that a projective transformation is suitable.
> 
> If I had a photograph taken above the imaged area, I could 
> use it as a reference image. However, such an image does 
> not exist. So there are two possibilities:
> 
> 1. Creating a simplified artificial reference image.
> 
> 2. Arbitrarily define mappings between points on converging 
> lines in an image to points on a rectangle.
> 
> Can you recommend a method of chosing or defining pairs of 
> points?
----------
  It looks to me as though you have posed for yourself a challenging problem, 
Okinawa Dolphin.

  Plane projective transformations are defined by equations of the rational 
form

 u = (A*x+B*y+C)/(G*x+H*y+I)
 v = (D*x+E*y+F)/(G*x+H*y+I)

where (u,v) are the transformed coordinates from (x,y) coordinates and A, B, 
C, D, E, F, G, H, I are nine arbitrary parameters.  Because of the division 
involved above, changing all nine parameters by the same scale factor doesn't 
alter the transformation, so there are really only eight degrees of freedom for 
such transformations.  This means that, in general, if you know four different 
pairs of corresponding (u,v) and (x,y) points, representing eight equations, 
the transformation for all points will then be uniquely determined.  
Accordingly, the 'cp2tform' and 'maketform' functions in the Images Toolbox 
you mentioned are indeed able to set up such transformations from (at least) 
four pairs of corresponding points.  (Happily, these functions get me off the 
hook for having to go through the necessary derivation from scratch.)

  However, faced with just a transformed image and no particular knowledge 
of the original image from which it was derived, leaves you with a lot of 
variation to investigate in trying to correct back to the original.  It may not be 
quite as hopeless as it first seems, though.  For example, suppose you know 
that four certain points in your image correspond to some four points in the 
original image with known relative positions, such as the four corners of what 
was formerly a square, the four corners of some quadrilateral of known 
shape, or perhaps four points in a figure of known original shape.  You just 
don't know the location, orientation, or size of that original shape.

  It is my understanding that if you use those first four points paired with any 
four points having the known original shape as the arguments of 'cp2tform' 
or 'maketform', they will give you a tranformation that is correct for the entire 
image except of course for its orientation, location, and size in the original 
form.  All that had been squares would be restored as squares, circles as 
circles, letter 'Q's as letter 'Q's.  The whole restored image would look like the 
original, except that you might have to stand on your head or use a 
magnifying glass to see it properly.  The trick, therefore, is to be able to 
recognize what the original shape was of some one reasonably large object in 
your distorted image and choose four corresponding point pairs in it to hand 
to 'cp2tform' or 'maketform'.

  In other words, the task of seeking a valid original image from a distorted 
one, involves only four degrees of freedom, rather than eight, because the 
other four degrees are involved in all the possible orientations, positions, and 
sizes that can occur in the original image.  Among those remaining four 
degrees of freedom, there should be one and only one combination that 
would look right.

  Is any of this of use to you?

Roger Stafford