Procházet zdrojové kódy

added viraltracin 2 mtpl space filp function

arefks před 8 měsíci
rodič
revize
2e82796756

+ 31 - 0
code/ProofOfModalities.py

@@ -0,0 +1,31 @@
+import nibabel as nib
+import numpy as np
+
+# Load NIfTI viral tracing data
+viral_tracing_img = nib.load(r"E:\2024_Ruthe_SND\output\Viral_tracing_flipped\Mop_projection_density_VT_mask.nii.gz"")
+viral_tracing_data = viral_tracing_img.get_fdata()
+
+# Load NIfTI mask data
+mask_img = nib.load(r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\Tract_Mask_registered\CC_Mop_dilated_registered.nii")
+mask_data = mask_img.get_fdata()
+
+# Load template
+template_img = nib.load(r"C:\Users\aswen\Desktop\Code\2024_Ruthe_SND\output\C57BL6_mouse.iso_registerd.nii.gz")
+template_data = template_img.get_fdata()
+
+# Check dimensions and shapes to ensure they align if needed
+print("Viral Tracing Data Shape:", viral_tracing_data.shape)
+print("Mask Data Shape:", mask_data.shape)
+print("Template Data Shape:", template_data.shape)
+
+# Now you can put them together based on your requirements
+# For example, if you want to overlay viral tracing data on the template using the mask
+# Assuming all data have the same dimensions
+
+# Apply mask to viral tracing data
+viral_tracing_masked = np.where(mask_data > 0, viral_tracing_data, 0)
+
+# Overlay masked viral tracing data on the template
+final_data = template_data + viral_tracing_masked
+
+# Save or further process the final_data as needed

+ 44 - 0
code/viralTracing2MTPL.py

@@ -0,0 +1,44 @@
+import os
+import argparse
+import numpy as np
+import nibabel as nib
+import glob
+
+def main():
+    parser = argparse.ArgumentParser(description="Resample multiple flo images using a reference image and an affine transformation file.")
+    parser.add_argument("-i", "--input", help="Input folder containing viraltracing images", required=True)
+    parser.add_argument("-o", "--output", help="Output folder for flipped images", required=True)
+    args = parser.parse_args()
+
+    # Create the output folder if it doesn't exist
+    if not os.path.exists(args.output):
+        os.makedirs(args.output)
+
+    # List all flo images in the input folder
+    flo_images = glob.glob(os.path.join(args.input, "**", "*.nii.gz"), recursive=True)
+
+    # Loop through flo images and perform resampling
+    for flo_image in flo_images:
+        output_filename = os.path.basename(flo_image).replace(".nii.gz", "_flipped.nii.gz")
+        output_path = os.path.join(args.output, output_filename)
+        mask_output_path = os.path.join(args.output, output_filename.replace("_flipped.nii.gz", "_mask.nii.gz"))
+        
+        # Load the image using nibabel
+        img = nib.load(flo_image)
+        data = img.get_fdata()
+        
+        # Perform the dimension manipulation to achieve the desired shape
+        data_swapped = np.swapaxes(data, 0, 2)  # Swap axes as per the desired shape (264, 160, 228) -> (228, 160, 264)
+        data_flipped = np.flip(data_swapped, axis=2)  # Flip along the third axis
+        
+        # Save the modified data back to a NIfTI file
+        img_flipped = nib.Nifti1Image(data_flipped, img.affine)
+        nib.save(img_flipped, output_path)
+        
+        # Create mask data
+        mask_data = np.where(data_flipped != 0, 1, 0)
+        mask_img = nib.Nifti1Image(mask_data.astype(np.uint8), img.affine)
+        nib.save(mask_img, mask_output_path)
+
+if __name__ == "__main__":
+    main()

binární
output/Viral_tracing_flipped/Mop_projection_density_VT_flipped.nii.gz


binární
output/Viral_tracing_flipped/Mop_projection_density_VT_mask.nii.gz


binární
output/Viral_tracing_flipped/Mos_projection_density_VT_flipped.nii.gz


binární
output/Viral_tracing_flipped/Mos_projection_density_VT_mask.nii.gz


binární
output/Viral_tracing_flipped/Optic_tract_projection_density_VT_flipped.nii.gz


binární
output/Viral_tracing_flipped/Optic_tract_projection_density_VT_mask.nii.gz


binární
output/Viral_tracing_flipped/SSp_ul_and_ll_projection_density_VT_flipped.nii.gz


binární
output/Viral_tracing_flipped/SSp_ul_and_ll_projection_density_VT_mask.nii.gz


binární
output/Viral_tracing_flipped/Thalamocortical_projection_density_VT_flipped.nii.gz


binární
output/Viral_tracing_flipped/Thalamocortical_projection_density_VT_mask.nii.gz


binární
output/Viral_tracing_flipped/average_template_50_from_website_flipped.nii.gz


binární
output/Viral_tracing_flipped/average_template_50_from_website_mask.nii.gz