# patch #8824: [octave forge] (image) added affine2d class

 Submitted by: Guy B Submitted on: Mon 07 Dec 2015 10:23:58 PM UTC Category: Forge : new feature Priority: 5 - Normal Status: None Privacy: Public Assigned to: None Open/Closed: Open

You are not logged in

## Discussion

Fri 23 Nov 2018 01:17:28 AM UTC, comment #9:

Hi, what Avinoam says makes sense to me. I'm attaching a patch with proposed changes and new BIST tests. I checked all my changes against online MATLAB docs. When I call affine2d or affine3d constructor with no parameters, it strangely fails but it shouldn't (I included two xtests demonstrating that). Is that a problem on my side?

Martin Janda <tojtoj>
Sun 21 May 2017 03:42:39 PM UTC, comment #8:

Consider the following script:

isTranslation(affine2d ([1 0 0; 0 -1 0; 0 0 1]))
isRigid(affine2d ([1 0 0; 0 -1 0; 0 0 1]))
isSimilarity(affine2d ([1 2 0; 3 4 0; 0 0 1]))
a = invert(affine2d ([1 2 0; 3 4 0; 10 20 1]))
b = affine2d(a.T)

The first 3 command give 1, which is wrong.
The last command fails with an error.

The reasons are:
isTranslation: the check is

check = all ((abs (abs (submatrix) - eye (this.Dimensionality)) < e^-10)(:));

which is wrong - the 2nd abs should be removed. It should be
check = all ((abs(submatrix - eye (this.Dimensionality)) < e^-10)(:));

Since I do not like those e^-10, I would prefer
check = all (abs (submatrix - eye (this.Dimensionality)) < eps)(:));
or even
check = !any (abs (submatrix - eye (this.Dimensionality)) > 0)(:));

Explanation: submatrix should be the Identity matrix (in the accuracy limits), so maybe the check should be different for
the diagonal entries (which should be 1), and the non-diagonal
(which should be 0)

isRigid: The submatrix should be a rotation matrix, without
scale or shear, so its determinant should be 1:
check = abs ((det (submatrix)) -1) < eps;

isSimilarity: The submatrix should be a rotation matrix multiplied by constant, so the condition is something like

s2 = submatrix*submatrix';
ans = all((abs(s2 - s2(1,1)*eye(2)) < ones(2)*eps)(:));

s2 should be the Identity Matrix multiplied by a constant.

When I do
a = invert(affine2d ([1 2 0; 3 4 0; 10 20 1]))
a.T(3,3)-1 = -1.1102e-016
so a.T(3,3) is not 1, and b = affine2d(a.T) fails.
there should be something like
this.T(:,3) = [0; 0; 1];

BTW,  line 72 should be:
this.T = inv (this.T);

Avinoam Kalma <avinoam>
Sat 20 May 2017 09:53:37 PM UTC, comment #7:

I have reviewed this and made a new class named affine to implement all of affine2d and affine3d in order to reduce code duplication.  Only the outputLimits method is still implemented on affine2d and affine3d.  Anyone can give a hand there?  See the branch affine-classes or

@Avinoam

can you be more explicit what was the problems? There was a lot of changes from you, but only a few were required to pass the new tests.

@motherboard

Can I have a proper name and valid email for the copyright notice?

CarnĂ« Draug <carandraug>
Wed 12 Apr 2017 07:46:00 PM UTC, comment #6:

I have fixed some problems with affine2d (the inverse was problematic).

Avinoam Kalma <avinoam>
Wed 09 Dec 2015 07:38:34 AM UTC, comment #5:

I mean, it is one of the possible arguments for imwarp (which are affine2d, affine3d or projective2d).
And this transform may be either built "by hand" by constructing it with the transformation matrix, or calculated using functions such as imregcorr, imregtform or estimateGeometricTransform.

since Matlab 2013a, it is no longer recommended to use imtransform, which used the transformation structure returned from maketform or cp2tform.

Guy B <motherboard>
Wed 09 Dec 2015 01:58:04 AM UTC, comment #4:

What do you mean with?

> It is used in imwarp, and is returned from functions such as imregcorr, imregtform and estimateGeometricTransform.

CarnĂ« Draug <carandraug>
Tue 08 Dec 2015 01:54:06 PM UTC, comment #3:

Added affine3d as well (very similar)

Guy B <motherboard>
Tue 08 Dec 2015 01:47:19 PM UTC, comment #2:

now the test is actually working...

Guy B <motherboard>
Tue 08 Dec 2015 12:52:27 PM UTC, comment #1:

fixed a bug in outputLimits, and added a test for it.

Guy B <motherboard>
Mon 07 Dec 2015 10:23:58 PM UTC, original submission:

affine2d class represents the affine transform of 2d vectors (as of matlab 2013a).
It is used in imwarp, and is returned from functions such as imregcorr, imregtform and estimateGeometricTransform.

Guy B <motherboard>

## Attached Files

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Comment:

Attached Files
file #45513:  affine_fix.patch added by tojtoj (6KiB - application/octet-stream)
file #40380:  affine2d.m added by avinoam (5KiB - application/octet-stream)
file #35665:  affine2dAnd3d.diff added by motherboard (5KiB - text/x-patch)
file #35664:  affine2d.diff added by motherboard (2KiB - text/x-patch)
file #35662:  affine2d.diff added by motherboard (1KiB - text/x-patch)
file #35658:  affine2d.diff added by motherboard (5KiB - text/x-patch)

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by tojtoj (Updated the item)
• -email is unavailable- added by tojtoj
• -email is unavailable- added by avinoam (Updated the item)
• -email is unavailable- added by avinoam
• -email is unavailable- added by motherboard (Submitted the item)
•

Do you think this task is very important?
This task has 0 encouragements so far.

Only logged-in users can vote.

## History

Date Changed by Updated Field Previous Value => Replaced by
2019-03-07 mtmiller Carbon-CopyRemoved 80942 -
2018-11-23 tojtoj Attached File- Added affine_fix.patch, #45513