Commit b02c93dc authored by Andrei-Claudiu Roibu's avatar Andrei-Claudiu Roibu 🖥
Browse files

updated load_files for evaluation

parent 7015c075
......@@ -197,15 +197,15 @@ def create_folder(path):
if not os.path.exists(path):
os.mkdir(path)
def load_file_paths(data_directory, targets_directory, data_list):
def load_file_paths(data_directory, data_list, targets_directory=None):
"""File Loader
This function returns a list of combined file paths for the input data and labelled output data.
Args:
data_directory (str): Path to input data directory
targets_directory (str): Path to labelled data (Y-equivalent)
data_list (str): Path to a .txt file containing the input files for consideration
targets_directory (str): Path to labelled data (Y-equivalent); None if during evaluation.
Returns:
file_paths (list): List containing the input data and target labelled output data
......@@ -220,8 +220,10 @@ def load_file_paths(data_directory, targets_directory, data_list):
else:
volumes_to_be_used = [files for files in os.listdir(data_directory)]
# mri/orig.mgz - TODO this needs to be changed in accordance with the actual file names - to be defined later!
file_paths = [[os.path.join(data_directory, volume, 'mri/orig.mgz'), os.join.path(targets_directory, volume, 'label.mgz')] for volume in volumes_to_be_used]
if targets_directory == None:
file_paths = [[os.path.join(data_directory, volume)] for volume in volumes_to_be_used]
else:
file_paths = [[os.path.join(data_directory, volume), os.join.path(targets_directory, volume)] for volume in volumes_to_be_used]
return file_paths
......@@ -248,13 +250,13 @@ def load_and_preprocess(file_paths, orientation):
return volume, label_map, header
def load(file_paths, orientation):
def load(file_path, orientation):
"""Load Data Function
This function loads the required data files and extracts relevant information from it.
Args:
file_paths (list): List containing the input data and target labelled output data
file_path (list): List containing the input data and target labelled output data
orientation (str): String detailing the current view (COR, SAG, AXL)
Returns:
......@@ -267,7 +269,7 @@ def load(file_paths, orientation):
"""
nifty_volume, label_map = nb.load(file_paths[0]), nb.load(file_paths[1])
volume, label_map = nifty_volume.get_fdata(), nift_labeled_volume.ged_fdata()
volume, label_map = nifty_volume.get_fdata(), label_map.ged_fdata()
# Do we need min-max normalization here? Will need to check when debuggint and testing
volume = (volume - np.min(volume)) / (np.max(volume) - np.min(volume))
......@@ -319,6 +321,26 @@ def set_orientation(volume, label_map, orientation):
else:
raise ValueError("Orientation value is invalid. It must be either >>coronal<<, >>axial<< or >>sagital<< ")
def load_and_preprocess_evaluation(file_path, orientation, min_max=True):
"""Load & Preprocessing before evaluation
This function loads a nifty file and returns its volume and header information
Args:
file_path (str): Path to the desired file
orientation (str): String detailing the current view (COR, SAG, AXL)
min_max (bool): Flag for inducing min-max normalization of the volume
Returns:
volume (np.array): Array of training image data of data type dtype.
header (class): 'nibabel.nifti1.Nifti1Header' class object, containing image metadata
Raises:
None
"""
nifty_volume = nb.load(file_path[0])
if __name__ == "__main__":
folder_location = '/well/win-biobank/projects/imaging/data/data3/subjectsAll/'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment