ProofOfModalities.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. import nibabel as nib
  2. import numpy as np
  3. # Load NIfTI viral tracing data
  4. viral_tracing_img = nib.load(r"E:\2024_Ruthe_SND\output\Viral_tracing_flipped\Mop_projection_density_VT_mask.nii.gz"")
  5. viral_tracing_data = viral_tracing_img.get_fdata()
  6. # Load NIfTI mask data
  7. mask_img = nib.load(r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Tract_Mask_registered\CC_Mop_dilated_registered.nii")
  8. mask_data = mask_img.get_fdata()
  9. # Load template
  10. template_img = nib.load(r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\C57BL6_mouse.iso_registerd.nii.gz")
  11. template_data = template_img.get_fdata()
  12. # Check dimensions and shapes to ensure they align if needed
  13. print("Viral Tracing Data Shape:", viral_tracing_data.shape)
  14. print("Mask Data Shape:", mask_data.shape)
  15. print("Template Data Shape:", template_data.shape)
  16. # Now you can put them together based on your requirements
  17. # For example, if you want to overlay viral tracing data on the template using the mask
  18. # Assuming all data have the same dimensions
  19. # Apply mask to viral tracing data
  20. viral_tracing_masked = np.where(mask_data > 0, viral_tracing_data, 0)
  21. # Overlay masked viral tracing data on the template
  22. final_data = template_data + viral_tracing_masked
  23. # Save or further process the final_data as needed