From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Image transformations Date: Thu, 13 Jun 2019 08:41:02 +0300 Message-ID: <835zpa11qp.fsf@gnu.org> References: <9A21DE14-BB5F-426E-BBB2-19C87930E733@gnu.org> <20190611200233.GA80199@breton.holly.idiocy.org> <83imta95z0.fsf@gnu.org> <20190612220746.GA89208@breton.holly.idiocy.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="210863"; mail-complaints-to="usenet@blaine.gmane.org" Cc: alan@idiocy.org, emacs-devel@gnu.org To: Alp Aker Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 13 07:47:55 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hbIaY-000sXv-HI for ged-emacs-devel@m.gmane.org; Thu, 13 Jun 2019 07:47:54 +0200 Original-Received: from localhost ([::1]:37046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbIaX-000190-DZ for ged-emacs-devel@m.gmane.org; Thu, 13 Jun 2019 01:47:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55533) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbIZK-0000uH-0j for emacs-devel@gnu.org; Thu, 13 Jun 2019 01:46:39 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:54053) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hbITw-0006uT-CX; Thu, 13 Jun 2019 01:41:05 -0400 Original-Received: from [176.228.60.248] (port=3901 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hbITu-0006Pu-D4; Thu, 13 Jun 2019 01:41:03 -0400 In-reply-to: (message from Alp Aker on Thu, 13 Jun 2019 00:16:36 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:237484 Archived-At: > From: Alp Aker > Date: Thu, 13 Jun 2019 00:16:36 -0400 > Cc: Eli Zaretskii , Emacs devel > > > 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.