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 the inverse deform filed? #71

Open
1190202328 opened this issue Mar 10, 2024 · 0 comments
Open

How to get the inverse deform filed? #71

1190202328 opened this issue Mar 10, 2024 · 0 comments

Comments

@1190202328
Copy link

1190202328 commented Mar 10, 2024

I am a beginner and I would like to know how TransMorph-diff obtains an inverse deformation field? Can I use this method below?

flow_mean = self.flow_mean(x)
log_sigma = self.flow_sigma(x)
noise = torch.randn(flow_mean.shape).cuda()
if self.training:
    flow = flow_mean + torch.exp(log_sigma / 2.0) * noise
else:
    flow = flow_mean  # + 1 * noise

# get inverse
inverse_flow = -flow

for _ in range(self.int_steps):
    deform_field = flow + self.low_res_id_transform
    flow_1 = self.bilinear(flow, deform_field)
    flow = flow_1 + flow
disp_field = F.interpolate(flow, scale_factor=self.sample_rate, mode='bilinear')
disp_field = self.scale_map(disp_field, np.array([1, 1]))
deform_field = disp_field + affine_map
warped_source = self.bilinear_img(source_image, deform_field)
self.res_flow_mean = flow
self.res_log_sigma = log_sigma

for _ in range(self.int_steps):
    inverse_deform_field = inverse_flow + self.low_res_id_transform
    inverse_flow_1 = self.bilinear(inverse_flow, inverse_deform_field)
    inverse_flow = inverse_flow_1 + inverse_flow
inverse_disp_field = F.interpolate(inverse_flow, scale_factor=self.sample_rate, mode='bilinear')
inverse_disp_field = self.scale_map(inverse_disp_field, np.array([1, 1]))
inverse_deform_field = inverse_disp_field + affine_map
warped_target = self.bilinear_img(target_image, inverse_deform_field)
self.inverse_res_flow_mean = inverse_flow

Thanks!

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

1 participant