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

cannot access tutorial on how to determine when to use nonrigid alignment in 3D reconstruction. #297

Open
yuling999666 opened this issue Dec 10, 2024 · 6 comments

Comments

@yuling999666
Copy link

Screenshot 2024-12-09 at 8 58 48 PM
@yuling999666
Copy link
Author

I have clicked "3D reconstruction with pairwise alignment", but 404 page not found. Thanks.

@YifanLu2000
Copy link
Contributor

Hi @yuling999666, apologies, the current link is indeed invalid. You can refer to this page instead, and we will update it as soon as possible.

Regarding when to use non-rigid alignment in 3D reconstruction, my opinion is that if a slice is significantly different from both the previous and the next slices, it may indicate the need for non-rigid alignment to restore its original shape. You can use the st.pl.overlay_slices_2d function to plot overlapping slices for better judgment.

As for how to perform non-rigid alignment, we generally use two approaches. Suppose the aligned slices from previous pairwise rigid alignment are stored in aligned_slices, you can do following:

  1. Directly concatenate surrounding slices as a reference.
spatial_key = 'align_spatial'
key_added = 'align_spatial_stage2'
neighbor_size = 1 # neighborhood size to concat
cur_idx = 1 # the slice that need to use nonrigid alignment
min_idx = max(0, cur_idx - neighbor_size)
max_idx = min(cur_idx + neighbor_size + 1, len(slices))
reference_neighbor_slices = ad.concat([aligned_slices[i] for i in range(min_idx,max_idx) if i != cur_idx])
transformed_slice = aligned_slices[cur_idx]
cur_aligned_slices, _= st.align.morpho_align(
    models=[reference_neighbor_slices, transformed_slice],
    spatial_key=spatial_key,
    key_added=key_added,
    device=device,
    rep_layer='X_pca',
    rep_field='obsm',
    dissimilarity='cos',
    # parameters that related to nonrigid
    beta=1e-1,
    lambdaVF=1e1,
    K = 50,
)
st.pl.overlay_slices_2d(slices = cur_aligned_slices, spatial_key = spatial_key, height=4, overlay_type='backward')
st.pl.overlay_slices_2d(slices = cur_aligned_slices, spatial_key = key_added + '_nonrigid', height=4, overlay_type='backward')

If the result is improved, you can insert the results into original slice:

aligned_slices[cur_idx].obsm[spatial_key][:,:2] = cur_aligned_slices[1].obsm[key_added + '_nonrigid']
  1. Perform Spateo linear interpolation using the previous and next slices, and then use the interpolated result as the reference. This will comming soon in the tutorial.

The related content will also be updated in the tutorial soon. I hope this helps!

@yuling999666
Copy link
Author

Hi @yuling999666, apologies, the current link is indeed invalid. You can refer to this page instead, and we will update it as soon as possible.

Regarding when to use non-rigid alignment in 3D reconstruction, my opinion is that if a slice is significantly different from both the previous and the next slices, it may indicate the need for non-rigid alignment to restore its original shape. You can use the st.pl.overlay_slices_2d function to plot overlapping slices for better judgment.

As for how to perform non-rigid alignment, we generally use two approaches. Suppose the aligned slices from previous pairwise rigid alignment are stored in aligned_slices, you can do following:

  1. Directly concatenate surrounding slices as a reference.
spatial_key = 'align_spatial'
key_added = 'align_spatial_stage2'
neighbor_size = 1 # neighborhood size to concat
cur_idx = 1 # the slice that need to use nonrigid alignment
min_idx = max(0, cur_idx - neighbor_size)
max_idx = min(cur_idx + neighbor_size + 1, len(slices))
reference_neighbor_slices = ad.concat([aligned_slices[i] for i in range(min_idx,max_idx) if i != cur_idx])
transformed_slice = aligned_slices[cur_idx]
cur_aligned_slices, _= st.align.morpho_align(
    models=[reference_neighbor_slices, transformed_slice],
    spatial_key=spatial_key,
    key_added=key_added,
    device=device,
    rep_layer='X_pca',
    rep_field='obsm',
    dissimilarity='cos',
    # parameters that related to nonrigid
    beta=1e-1,
    lambdaVF=1e1,
    K = 50,
)
st.pl.overlay_slices_2d(slices = cur_aligned_slices, spatial_key = spatial_key, height=4, overlay_type='backward')
st.pl.overlay_slices_2d(slices = cur_aligned_slices, spatial_key = key_added + '_nonrigid', height=4, overlay_type='backward')

If the result is improved, you can insert the results into original slice:

aligned_slices[cur_idx].obsm[spatial_key][:,:2] = cur_aligned_slices[1].obsm[key_added + '_nonrigid']
  1. Perform Spateo linear interpolation using the previous and next slices, and then use the interpolated result as the reference. This will comming soon in the tutorial.

The related content will also be updated in the tutorial soon. I hope this helps!

Thanks for clarification. It really helps a lot!

@yuling999666
Copy link
Author

Hi Yifan, one more question. When you did 3D reconstruction in figure 3 for human metastatic lymph node, did you use non-rigid alignment? Thanks.

@YifanLu2000
Copy link
Contributor

Hi @yuling999666, I think we didn't use the nonrigid alignment for 3D reconstruction for human metastatic lymph node dataset

@yuling999666
Copy link
Author

Hi @yuling999666, I think we didn't use the nonrigid alignment for 3D reconstruction for human metastatic lymph node dataset

Thanks for quick response. I appreciate it.

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

2 participants