AffineTransformation for

16 views
Skip to first unread message

Masoud Ramuz

unread,
Nov 12, 2018, 8:41:58 AM11/12/18
to Icy imaging
Dear Icy,

I have two sets of coordinates, and I want to transform one to fit to the other.
Basically I'm creating an image for a region to tightly fit into, corrected for rotation/shearing:
I have 4 sets of point-coordinates (X Y) for the initial region, and 4 sets for the target region.

I was wondering if Icy has any methods for this? I've seen the AffineTransform method of OpenCV which sounds like it does exactly what I need (https://docs.opencv.org/3.4.3/d4/d61/tutorial_warp_affine.html), but trying to use OpenCV methods in a plugin gives me the following error:
java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J
Which indicates that the library file cannot be found? The same code works fine in a standalone java project.
Perhaps linking to libraries works differently for plugins? I'm a bit new to java so if you could explain how that works it might help.
Otherwise suggestions to do an affinetransformation without openCV would be appreciated, I'm not great at math so I was hoping to use the openCV methods to generate the needed matrices for me out of the sets of points.

For testing code, see here:
I cannot get this to work in an Icy plugin.

Stephane

unread,
Nov 12, 2018, 11:48:58 AM11/12/18
to Icy imaging
Hi Masoud,

I'm using VTK to do that (it can do it in 3D) but OpenCV seems to be able to do it as well.

Here's the code i'm using to do it with VTK (so you don't need to rely on OpenCV) :

  final vtkPoints srcPoints = VtkUtil.getPoints(wantedPtsArray);
 
final vtkPoints dstPoints = VtkUtil.getPoints(realPtsArray);

 
final vtkLandmarkTransform vtkTrans = new vtkLandmarkTransform();

  vtkTrans
.SetSourceLandmarks(srcPoints);
  vtkTrans
.SetTargetLandmarks(dstPoints);
  vtkTrans
.SetModeToRigidBody();
  vtkTrans
.Modified();
  vtkTrans
.Update();


 
// transform new point

  vtkTrans
.TransformPoint(..);
 
// get transformation matrix

 
final vtkMatrix4x4 mat = vtkTrans.GetMatrix();

But if you prefer to use OpenCV you can do it as well, but in this case just add the OpenCV plugin for Icy as a dependency for your plugin so it will be automatically installed when you install your plugin in Icy :)

Hope that helps.

Best,

- Stephane
Reply all
Reply to author
Forward
0 new messages