all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Alp Aker <alptekin.aker@gmail.com>
Cc: alan@idiocy.org, emacs-devel@gnu.org
Subject: Re: Image transformations
Date: Thu, 13 Jun 2019 08:41:02 +0300	[thread overview]
Message-ID: <835zpa11qp.fsf@gnu.org> (raw)
In-Reply-To: <CACxch4oMhV_o8VX2GLYXrSwA1ijF0J3sO7eEqyWm9Dxoq5CPAg@mail.gmail.com> (message from Alp Aker on Thu, 13 Jun 2019 00:16:36 -0400)

> From: Alp Aker <alptekin.aker@gmail.com>
> Date: Thu, 13 Jun 2019 00:16:36 -0400
> Cc: Eli Zaretskii <eliz@gnu.org>, Emacs devel <emacs-devel@gnu.org>
> 
> > matrix:
> > 0.000000 1.000000 0.000000
> > -1.000000 0.000000 232.000000
> > 0.000000 0.000000 1.000000
> >
> > I don’t know exactly what that means.  The 1 and -1 are shearing the
> > image in the x and y dimensions. The 232 is moving the image in the y
> > dimension
> 
> This is a transformation matrix using so-called homogenous coordinates:
> 
> https://en.wikipedia.org/wiki/Transformation_matrix#Affine_transformations

Right, I got that far, it's the details that somewhat confuse me, see
below.

> It's a clockwise 90 degree rotation followed by a translation along the y
> axis.

This already goes contrary to my geometric intuition, please bear with
me.  The rotation is around the (0,0) origin, i.e. around the top-left
corner of the original image, right?  If so, the rotation should have
been followed by a translation along the X axis, not Y, because
rotating a 333-pixel wide, 233-pixel high image 90 deg clockwise
produces a 233-pixel wide, 333-pixel high image that is entirely to
the LEFT of the Y axis.  Here's ASCII-art representation of that:

    +------------------+> X        +----------+-------------------> X
    |                  |           |          |
    |                  |           |          | 
    |                  |           |          |
    |                  |   ===>    |          |
    +------------------+           |          |
    |                              |          |
    |                              |          |
    |                              |          |
    |                              +----------+
    |                                         |
    V                                         V
    Y                                         Y

The above is just after the rotation around (0,0).  Is that correct,
or am I missing something?

I also tried to approach this from the matrix notation aspect.  Is the
following the correct equations of computing (x',y'), the new
coordinates of any pixel of the image, from its original coordinates
(x,y)?

  x' = m11 * x + m12 * y + tx
  y' = m21 * x + m22 * y + ty

where the factors are related to the matrix as follows:

   m[0][0] = m11 | m[0][1] = m12 | m[0][2] = 0
   --------------+---------------+-------------
   m[1][0] = m21 | m[1][1] = m22 | m[1][2] = 0
   --------------+---------------+-------------
   m[2][0] = tx  | m[2][1] = ty  | m[2][2] = 1

If the above is correct, then the transformation of the top-left
corner of the original image, whose original coordinates are (0,0),
yield

  x' = 0 * x + -1 * y +   0 = 0
  y' = 1 * x +  0 * y + 232 = 232

which is incorrect, since the correct coordinates should be (233,0),
not (0,232).  (The 232 vs 233 is some kind of round-off, but let's
ignore that for now.)

What am I missing here?

There's also the issue of cropping, which the current code in image.c
seems to represent as some kind of translation with change in image
size.  But my, perhaps incorrect, interpretation of translation is
that the entire image is shifted along X and Y axes, which is not what
cropping is about, AFAIU.  Again, I'm probably missing something very
fundamental here.

> In general you can't assign a geometric meaning to m11, m12, m21, m22
> taken individually; whether they represent rotation, shearing, or scaling
> depends on their relative values.
> 
> > I believe we take the x and y coordinates and convert them into a 3x1
> matrix
> > and multiply that by the transformation matrix and it gives us a new set
> of
> > coordinates.
> >
> >    [x]   [m11 m12 m13]
> >    [y] X [m21 m22 m23] = [x’ y’ 0]
> >    [0]   [m31 m32 m33]
> 
> You need to use 1 instead of 0 when translating from Cartesian to homogenous
> coordinates.  That is, given a point (x, y), you find (x', y') as
> follows.  Multiply (x, y, 1) by the transformation matrix.  Let the result
> be
> (a, b, c).  Then the new point (x', y') in Cartesian coordinates is (a/c,
> b/c).
> 
> When dealing only with affine transformations the procedure is
> simpler.  Such transformations can always be described by a matrix
> where m31 == m32 == 0 and m33 == 1.  In that case, the result of
> multiplication will have the form (a, b, 1), so x' == a and y' == b.

Sorry, now I'm even more confused: aren't we dealing with affine
transformations?  Then how are homogeneous coordinates related to
this?  And does that mean the formulae for calculating (x',y') I show
above are incorrect?

Thanks.



  reply	other threads:[~2019-06-13  5:41 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11  5:10 Image transformations Eli Zaretskii
2019-06-11 20:02 ` Alan Third
2019-06-12 15:30   ` Eli Zaretskii
2019-06-12 22:07     ` Alan Third
2019-06-12 22:15       ` Alan Third
2019-06-13  4:16       ` Alp Aker
2019-06-13  5:41         ` Eli Zaretskii [this message]
2019-06-13  9:19           ` Alp Aker
2019-06-13 13:05             ` Eli Zaretskii
2019-06-13 15:57               ` Alp Aker
2019-06-13 16:20                 ` Eli Zaretskii
2019-06-13 19:00                   ` Richard Copley
2019-06-13 19:29                     ` Eli Zaretskii
2019-06-14 10:45                     ` Alp Aker
2019-06-14 10:55                       ` Richard Copley
2019-06-14 11:45                         ` YAMAMOTO Mitsuharu
2019-06-14 11:59                         ` Alp Aker
2019-06-13 16:12           ` Alan Third
2019-06-13 17:05             ` Eli Zaretskii
2019-06-13 19:35               ` Richard Copley
2019-06-13  5:48       ` Eli Zaretskii
2019-06-13 16:58         ` Alan Third
2019-06-13 17:11           ` Eli Zaretskii
2019-06-13 19:27             ` Alan Third
2019-06-13 19:39               ` Alan Third
2019-06-13 19:47               ` Eli Zaretskii
2019-06-13 22:26                 ` Alan Third
2019-06-14  7:05                   ` Eli Zaretskii
2019-06-14  9:57                     ` Stefan Monnier
2019-06-14 10:57                       ` Eli Zaretskii
2019-06-14 11:21                         ` Richard Copley
2019-06-14 12:06                           ` Eli Zaretskii
2019-06-14 12:49                             ` Richard Copley
2019-06-14 14:16                               ` Yuri Khan
2019-06-14 14:43                               ` Eli Zaretskii
2019-06-14 15:55                                 ` Richard Copley
2019-06-15 11:00                                   ` Alan Third
2019-06-15 11:34                                     ` Eli Zaretskii
2019-06-15 10:42                     ` Alan Third
2019-06-15 11:31                       ` Eli Zaretskii
2019-06-16 15:22                         ` Alan Third
2019-06-16 16:34                           ` Eli Zaretskii
2019-06-17 21:13                             ` Alan Third
2019-06-19 17:56                               ` Eli Zaretskii
2019-06-24 17:54                               ` Eli Zaretskii
2019-06-24 19:50                                 ` Stefan Monnier
2019-06-25  2:33                                   ` Eli Zaretskii
2019-06-25  3:28                                     ` Stefan Monnier
2019-06-25  4:34                                       ` Eli Zaretskii
2019-06-25 14:43                                         ` Stefan Monnier
2019-06-25 15:35                                           ` Eli Zaretskii
2019-06-26  0:28                                             ` YAMAMOTO Mitsuharu
2019-06-26 15:34                                               ` Eli Zaretskii
2019-06-27  3:37                                                 ` YAMAMOTO Mitsuharu
2019-06-27 13:13                                                   ` Eli Zaretskii
2019-06-25 18:33                                 ` Alan Third
2019-06-25 18:57                                   ` Eli Zaretskii
2019-06-27 13:59                                     ` Eli Zaretskii
2019-06-28 18:36                                       ` Alan Third
2019-06-28 19:50                                         ` Eli Zaretskii
2019-06-29 11:55                                           ` Eli Zaretskii
2019-06-29 19:51                                             ` Alan Third
2019-06-29 19:49                                           ` Alan Third
2019-06-29 19:53                                             ` Lars Ingebrigtsen
2019-06-30 14:38                                               ` Alan Third
2019-06-30 15:24                                                 ` Lars Ingebrigtsen
2019-07-25 19:40                                                   ` Lars Ingebrigtsen
2019-07-26  6:10                                                     ` Eli Zaretskii
2019-07-26  6:46                                                       ` Lars Ingebrigtsen
2019-07-26  8:06                                                         ` Eli Zaretskii
2019-07-26  8:23                                                           ` Lars Ingebrigtsen
2019-07-26  8:24                                                             ` Lars Ingebrigtsen
2019-07-26  8:33                                                               ` Eli Zaretskii
2019-07-26  8:58                                                                 ` Lars Ingebrigtsen
2019-07-26  9:13                                                                   ` Eli Zaretskii
2019-07-26 10:23                                                                     ` Lars Ingebrigtsen
2019-07-26 14:08                                                                   ` Stefan Monnier
2019-07-26  8:32                                                             ` Eli Zaretskii
2019-06-29 21:05                                             ` Stefan Monnier
2019-06-30 15:12                                             ` Eli Zaretskii
2019-06-30 19:10                                               ` Alan Third
2019-07-01 14:55                                                 ` Eli Zaretskii
2019-06-18 11:01                       ` Tak Kunihiro
2019-06-13 17:41           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=835zpa11qp.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=alan@idiocy.org \
    --cc=alptekin.aker@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.