<jupyter_start><jupyter_text>Exploratory Data Analysis<jupyter_code>import matplotlib.pylab as plt
import numpy as np
import nibabel as nib # For loading Nifti images
import os
import glob
data_path = "C:\\Users\\rober\\OneDrive\\Documents\\Datasets\\CC359\\Original\\" # Images' path
masks_path = "C:\\Users\\rober\\OneDrive\\Documents\\Datasets\\CC359\\STAPLE\\" # Brain segmentations' path
source_domain = ["philips_15", "siemens_15","ge_15"] # 1.5 T images
target_domain = ["philips_3", "siemens_3","ge_3"] # 3 T images
# Min-max dimensions and intensities source domain
dims_s = [ ]
min_max_s = []
regex = data_path +"*_15_*.nii.gz"
imgs_list = glob.glob(regex)

for ii in imgs_list:
    vol = nib.load(ii).get_fdata()
    dims_s.append(vol.shape)
    min_max_s.append((vol.min(),vol.max()))  

dims_s = np.asarray(dims_s) # COnvert list to array
min_max_s = np.asarray(min_max_s)

print("Min dimensions:")
print(dims_s.min(axis = 0))
print("Max dimensions:")
print(dims_s.max(axis = 0))
print("Min-max values:")
print(min_max_s.min(),min_max_s.max())
# Min-max dimensions and intensities target domain
dims_t = [ ]
min_max_t = []

regex = data_path +"*_3_*.nii.gz"
imgs_list = glob.glob(regex)

for ii in imgs_list:
    vol = nib.load(ii).get_fdata()
    dims_t.append(vol.shape)
    min_max_t.append((vol.min(),vol.max()))

dims_t = np.asarray(dims_t) # COnvert list to array
min_max_t = np.asarray(min_max_t)

print("Min dimensions:")
print(dims_t.min(axis = 0))
print("Max dimensions:")
print(dims_t.max(axis = 0))
print("Min-max values:")
print(min_max_t.min(),min_max_t.max())
b = 500
# Sample histograms source domain
plt.figure(figsize = (12,6))
for (c,ii) in enumerate(source_domain):
    source_domain_sample = glob.glob(data_path + "*" + ii +"*")[0]
    img = nib.load(source_domain_sample).get_fdata()
    img = img/img.max()
    plt.subplot(3,1,c+1)
    n,bins, patches = plt.hist(img.flatten(), bins=b, range=(0, 1),density = True)
    plt.xlim(0,1)
    plt.ylim(0,n[5])
    plt.title(ii)
plt.show()
# Sample histograms target domain
plt.figure(figsize = (12,6))
for (c,ii) in enumerate(target_domain):
    source_domain_sample = glob.glob(data_path + "*" + ii +"*")[0]
    img = nib.load(source_domain_sample).get_fdata()
    img = img/img.max()
    plt.subplot(3,1,c+1)
    n,bins, patches = plt.hist(img.flatten(), bins=b, range=(0, 1),density = True)
    plt.xlim(0,1)
    plt.ylim(0,n[5])
    plt.title(ii)
plt.show()
plt.figure(figsize = (12,6))
for (c,ii) in enumerate(source_domain):
    source_domain_sample = glob.glob(data_path + "*" + ii +"*")[0]
    img = nib.load(source_domain_sample).get_fdata()
    H,W,Z = img.shape
    img = img/img.max()
    plt.figure(figsize = (12,6))
    plt.subplot(1, 3, 1)
    plt.imshow(img[H//2], cmap = "gray")
    plt.subplot(1, 3, 2)
    plt.imshow(img[:,W//2,:], cmap = "gray")
    plt.subplot(1, 3, 3)
    plt.imshow(img[:,:,Z//2], cmap = "gray")
    plt.title(ii)
    plt.show()
plt.figure(figsize = (12,6))
for (c,ii) in enumerate(target_domain):
    source_domain_sample = glob.glob(data_path + "*" + ii +"*")[0]
    img = nib.load(source_domain_sample).get_fdata()
    H,W,Z = img.shape
    img = img/img.max()
    plt.figure(figsize = (12,6))
    plt.subplot(1, 3, 1)
    plt.imshow(img[H//2], cmap = "gray")
    plt.subplot(1, 3, 2)
    plt.imshow(img[:,W//2,:], cmap = "gray")
    plt.subplot(1, 3, 3)
    plt.imshow(img[:,:,Z//2], cmap = "gray")
    plt.title(ii)
    plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18651362984218078, 'fraction_numerical': 0.026398852223816355, 'mean_word_length': 4.0964912280701755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '660344', 'license': 'MIT', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1446, 'n_words': 261, 'path': 'SLURM/Unet-Segmentation/EDA.ipynb', 'repo_name': 'rmsouza01/ENSF619.2', 'size': '3485'}