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

How to get point in moving image? #16

Open
sunxirui310 opened this issue Aug 3, 2019 · 4 comments
Open

How to get point in moving image? #16

sunxirui310 opened this issue Aug 3, 2019 · 4 comments

Comments

@sunxirui310
Copy link

Im trying to get a point warped in moving image. something goes wrong. someone give me a hand? thx!
image

class SimilarityTransformation(RigidTransformation):
    ......    
    def _get_transformation_matrix(self):
        self._compute_transformation()
        return self._compute_transformation_matrix()

in file 'affine_registration_2d.py' i added:

matT = transformation._get_transformation_matrix().data.cpu().numpy()
matT = np.vstack((matT,[0,0,1]))# make matT 3*3
matT_inv = np.linalg.inv(matT)# inv(matT)
...
#draw point in moving image
px=128
py=64
plt.subplot(131)
plt.imshow(fixed_image.numpy(), cmap='gray')
plt.plot(px, py, 'ro')
plt.title('Fixed Image')

plt.subplot(132)
plt.imshow(moving_image.numpy(), cmap='gray')
pxM=(px/256*matT_inv[0][0]+py/256*matT_inv[0][1]+matT_inv[0][2])*256
pyM=(px/256*matT_inv[1][0]+py/256*matT_inv[1][1]+matT_inv[1][2])*256
plt.plot(pxM,pyM, 'r+')
plt.title('Moving Image')
@RobinSandkuehler
Copy link
Collaborator

Hi,
sorry for the late answer. You can use

points_transformed = al.Points.transform(points, displacement)

to transform points. Hope this could help you.

@sunxirui310
Copy link
Author

thx,i've got pytorch transform matrix -> opencv transform matrix . seems to make a detour.
just 2D works.

def theta2param(theta, w,h):
    if theta.shape == (2,3):
        theta = np.vstack((theta,[0,0,1]))
    theta = np.linalg.inv(theta)
    param = np.zeros([2,3])
    param[0,0] = theta[0,0]
    param[0,1] = theta[0,1] / h * w
    param[0,2] = (theta[0,2] - theta[0,0] - theta[0,1] + 1) * w / 2
    param[1,0] = theta[1,0] / w * h
    param[1,1] = theta[1,1]
    param[1,2] = (theta[1,2] - theta[1,0] - theta[1,1] + 1) * h / 2   
    return param

image

@RossoneriMaldini
Copy link

Hi,
sorry for the late answer. You can use

points_transformed = al.Points.transform(points, displacement)

to transform points. Hope this could help you.

Hi,
Thanks for sharing!

I'm trying to find corresponding point in registration. Could you please tell me the displacement meaning in your implementation? I check the value of displacement and find values between [-0.01,0.01] in both x and y direction(in kernel_registration_2d.py). So displacement not mean pixel translation in each direction?

I'm trying this way but encounter error...
Traceback (most recent call last):
File "kernel_registration_2d.py", line 139, in
main()
File "kernel_registration_2d.py", line 108, in main
points_transformed = al.Points.transform(pts1, displacement)
File "/home/share/kaka/ML/airlab/airlab/utils/points.py", line 113, in transform
transformed_points[i, :] = df_transform.TransformPoint(points[i, :])
File "/home/kaka/anaconda3/envs/pytorch/lib/python3.6/site-packages/SimpleITK/SimpleITK.py", line 5016, in TransformPoint
return _SimpleITK.Transform_TransformPoint(self, point)
TypeError: in method 'Transform_TransformPoint', argument 2 of type 'std::vector< double,std::allocator< double > > const &'

@yangxue0827
Copy link

my code:

displacement = transformation.get_displacement()
warped_image = al.transformation.utils.warp_image(moving_image, displacement)
polybox = [[654, 260], [654, 290], [700, 290], [700, 260]]
warped_polybox = al.Points.transform(np.array(polybox).reshape([-1, 2]), displacement)
displacement = al.create_displacement_image_from_image(displacement, moving_image)

error:

Traceback (most recent call last):
  File "/Users/yangxue/Desktop/yangxue/code/airlab/examples/demo.py", line 151, in <module>
    main()
  File "/Users/yangxue/Desktop/yangxue/code/airlab/examples/demo.py", line 99, in main
    warped_polybox = al.Points.transform(np.array(polybox).reshape([-1, 2]), displacement)
  File "/Users/yangxue/Desktop/yangxue/code/airlab/airlab/utils/points.py", line 105, in transform
    raise Exception("Datatype of displacement field not supported.")
Exception: Datatype of displacement field not supported.

So I used the wrong displacement. How do I get the correct displacement? Can you give an example?

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

No branches or pull requests

4 participants