Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about affine transformation #44

Open
mkeays opened this issue Jun 13, 2019 · 3 comments
Open

Question about affine transformation #44

mkeays opened this issue Jun 13, 2019 · 3 comments

Comments

@mkeays
Copy link

mkeays commented Jun 13, 2019

I am trying out the affine() function with a simple example matrix, and I noticed something that puzzled me. It seems to add an extra row and column to the transformed matrix even if the scaling factors are both 1:

> pre_aff <- matrix( rep( 1, 16 ), nrow = 4 )
> pre_aff
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    1    1    1    1
[3,]    1    1    1    1
[4,]    1    1    1    1
> mat <- matrix( c( 1, 0, 2, 0, 1, 3 ), nrow = 3 )
> mat
     [,1] [,2]
[1,]    1    0
[2,]    0    1
[3,]    2    3
> affine( pre_aff, mat, output.dim = c( 10, 10 ), antialias = FALSE )
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    0    0    0    0    0    0    0    0    0     0
 [2,]    0    0    1    1    1    1    1    0    0     0
 [3,]    0    0    1    1    1    1    1    0    0     0
 [4,]    0    0    1    1    1    1    1    0    0     0
 [5,]    0    0    1    1    1    1    1    0    0     0
 [6,]    0    0    1    1    1    1    1    0    0     0
 [7,]    0    0    0    0    0    0    0    0    0     0
 [8,]    0    0    0    0    0    0    0    0    0     0
 [9,]    0    0    0    0    0    0    0    0    0     0
[10,]    0    0    0    0    0    0    0    0    0     0

Is this expected behaviour? I thought that the above transformation matrix would simply translate the matrix to a new position but leave the dimensions the same as before the transformation.

@mkeays
Copy link
Author

mkeays commented Jun 13, 2019

I just noticed that applying the affine() function with antialias = TRUE does not do this:

> affine( pre_aff, mat, output.dim = c( 10, 10 ), antialias = TRUE )
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    0    0    0    0    0    0    0    0    0     0
 [2,]    0    0    0    0    0    0    0    0    0     0
 [3,]    0    0    0    1    1    1    1    0    0     0
 [4,]    0    0    0    1    1    1    1    0    0     0
 [5,]    0    0    0    1    1    1    1    0    0     0
 [6,]    0    0    0    1    1    1    1    0    0     0
 [7,]    0    0    0    0    0    0    0    0    0     0
 [8,]    0    0    0    0    0    0    0    0    0     0
 [9,]    0    0    0    0    0    0    0    0    0     0
[10,]    0    0    0    0    0    0    0    0    0     0

@aoles
Copy link
Owner

aoles commented Jun 14, 2019

Thank you for reporting this! Might be some rounding issue occurring in bilinear filtering step, will need to investigate.

If you are interested in performing pixel transformations which have a 1:1 pixel mapping between the input and the output such as translation by whole pixel coordinates or rotation by multiplies of 90 degrees consider using affine() with filter = "none". Another option is to use wrapper functions translate() or rotate() which set the appropriate arguments to for you.

Cheers,
Andrzej

@mkeays
Copy link
Author

mkeays commented Jun 18, 2019

Hi Andrzej,

Thanks very much for looking at this! I am quite new to this sort of analysis so I was trying out the function with a simple example to see what the result would be. I have a dataset from a collaborator with images and a transformation matrix defining an affine transform to align them. I'll try out the function with filter = "none" as you suggest.

Thanks,
Maria

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants