javarfiji

Import of 3D affine transformation build in Java to R


I have a question related to affine transformations (between the <affine> tags). I am extracting the following two affine transformations from an xml file (full xml file here) created with the BigDataViewer Fiji plugin created with Java, using the AffineTransform3D function:

<ViewRegistrations>
<ViewRegistration timepoint="0" setup="0">
  <ViewTransform type="affine">
    <Name>Fast 3d geometric hashing (rotation invariant), AffineModel3D on [beads (c=0)]</Name>
    <affine>1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0</affine>
  </ViewTransform>
  <ViewTransform type="affine">
    <Name>calibration</Name>
    <affine>1.9998662296836334 0.0 0.0 0.0 0.0 1.9998662296836334 0.0 0.0 0.0 0.0 1.9998662296836334 0.0</affine>
  </ViewTransform>
</ViewRegistration>

I would like to import the two affine transformation in R, using the buildAffine() function from the R package {RNiftyReg}, then compute their composition using composeTransforms() from {RNiftyReg}.

buildAffine(translation = c(0, 0, 0), scales = c(1, 1, 1), skews = c(0, 0,0),
  angles = c(0, 0, 0), source = NULL, target = NULL,
  anchor = c("none", "origin", "centre", "center"))

My question:
The affine transformations above are stored in a vector of 12 indices. buildAffine() requires as input parameters the values for the translations, scales, skews and angles.
I would like to know which value correspond to what.


Solution

  • I'm mostly an R user but here goes: The names of the varaibles in hte Java call are:

     dat <- scan (text="double xx, double yx, double zx, double tx, double xy, double yy, double zy, double ty, double xz, double yz, double zz, double tz", what="")
    dat <- dat[dat != "double"]
    matrix(dat,4)
          [,1]  [,2]  [,3] 
    [1,] "xx," "xy," "xz,"
    [2,] "yx," "yy," "yz,"
    [3,] "zx," "zy," "zz,"
    [4,] "tx," "ty," "tz" 
    

    This page documents how an affine transformation could be encoded with the only difference being that the 4x3 matrix is transposed: https://o7planning.org/en/11157/javafx-transformations-tutorial

     t( matrix(dat,4) )
         [,1]  [,2]  [,3]  [,4] 
    [1,] "xx," "yx," "zx," "tx,"
    [2,] "xy," "yy," "zy," "ty,"
    [3,] "xz," "yz," "zz," "tz" 
    

    So the matrix would be applied to a vector of c(x,y,z,1) to get an output of:

    enter image description here