diff --git a/PyNutil/folder_of_segmentations_to_meshview.py b/PyNutil/folder_of_segmentations_to_meshview.py index 7abbfd81d261ba2a638c3d9f5782c3bd7fbc91b0..82775778a7dba50eec2e9046073ee2b0cd6858de 100644 --- a/PyNutil/folder_of_segmentations_to_meshview.py +++ b/PyNutil/folder_of_segmentations_to_meshview.py @@ -5,6 +5,7 @@ import pandas as pd import nrrd import numpy as np import csv +import json from datetime import datetime diff --git a/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py b/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py index 20cf0323370ab27961c7261071c225a44575187f..47fc06ab0b53f4c454ac045d1761faccb2d0a304 100644 --- a/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py +++ b/PyNutil/folder_of_segmentations_to_meshview_multithreaded.py @@ -5,29 +5,22 @@ import pandas as pd import nrrd import numpy as np import csv +import json from datetime import datetime -#import json and use it to define volume_path, segmentation_folder, alignment_json, label_path, colour, allen_colours - +#import json, use to define input parameters +with open('../input.json', 'r') as f: + input = json.load(f) +#print(input) #import our function for converting a folder of segmentations to points -from PyNutil import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded -label_path = "../annotation_volumes//allen2022_colours.csv" -colour = [255, 0, 255] -volume_path = "../annotation_volumes//annotation_10_reoriented.nrrd" -data, header = nrrd.read(volume_path) -points_json_path = "../outputs/points.json" -segmentation_folder = "../test_data/oneSection15" -alignment_json = "../test_data/C68_nonlinear_no_markers.json" -allen_colours = "../annotation_volumes//allen2022_colours.csv" -counts_per_label_name = "../outputs/counts_per_allenID.csv" +from coordinate_extraction import FolderToAtlasSpace, labelPoints, WritePointsToMeshview, FolderToAtlasSpaceMultiThreaded startTime = datetime.now() - #now we can use our function to convert the folder of segmentations to points -points = FolderToAtlasSpaceMultiThreaded(segmentation_folder,alignment_json, pixelID=colour, nonLinear=True) +points = FolderToAtlasSpaceMultiThreaded(input["segmentation_folder"],input["alignment_json"], pixelID=[255,0,255], nonLinear=True) time_taken = datetime.now() - startTime @@ -36,12 +29,13 @@ print(f"Folder to atlas took: {time_taken}") #then the path to the volume #read the label files -label_df = pd.read_csv(label_path) +label_df = pd.read_csv(input["label_path"]) #read the annotation volume, it also has a header but we don't need it +data, header = nrrd.read(input["volume_path"]) #now we can get the labels for each point labels = labelPoints(points, data, scale_factor=2.5) #save points to a meshview json -WritePointsToMeshview(points, labels,points_json_path, label_df) +WritePointsToMeshview(points, labels, input["points_json_path"], label_df) #Task: # Make a pandas dataframe @@ -56,7 +50,7 @@ counts_per_label = list(zip(counted_labels,label_counts)) df_counts_per_label = pd.DataFrame(counts_per_label, columns=["allenID","pixel count"]) -df_allen_colours =pd.read_csv(allen_colours, sep=",") +df_allen_colours =pd.read_csv(input["allen_colours"], sep=",") df_allen_colours #look up name, r, g, b in df_allen_colours in df_counts_per_label based on "allenID" @@ -80,7 +74,7 @@ df_counts_per_label_name = pd.DataFrame(new_rows) df_counts_per_label_name # write to csv file -df_counts_per_label_name.to_csv(counts_per_label_name, sep=";", na_rep='', index= False) +df_counts_per_label_name.to_csv(input["counts_per_label_name"], sep=";", na_rep='', index= False) #r = df_allen_colours["r"] #g = df_allen_colours["g"] diff --git a/input.json b/input.json new file mode 100644 index 0000000000000000000000000000000000000000..a3596365e91c1f9c2968b31ea2ceb138be62c940 --- /dev/null +++ b/input.json @@ -0,0 +1,10 @@ +{"label_path": "../annotation_volumes//allen2022_colours.csv", + "colour": "[255, 0, 255]", + "nonlinear": "True", + "volume_path": "../annotation_volumes//annotation_10_reoriented.nrrd", + "points_json_path": "../outputs/points.json", + "segmentation_folder": "../test_data/oneSection15", + "alignment_json": "../test_data/C68_nonlinear_no_markers.json", + "allen_colours": "../annotation_volumes//allen2022_colours.csv", + "counts_per_label_name": "../outputs/counts_per_allenID.csv" +} \ No newline at end of file diff --git a/input/input.json b/input/input.json new file mode 100644 index 0000000000000000000000000000000000000000..68434ceda0d756a31b8998958b8e3e0cb85d53aa --- /dev/null +++ b/input/input.json @@ -0,0 +1,10 @@ +{"label_path": "../annotation_volumes//allen2022_colours.csv", + "colour": "[255, 0, 255]", + "volume_path": "../annotation_volumes//annotation_10_reoriented.nrrd", + "data, header": "nrrd.read(volume_path)", + "points_json_path": "../outputs/points.json", + "segmentation_folder": "../test_data/oneSection15", + "alignment_json": "../test_data/C68_nonlinear_no_markers.json", + "allen_colours": "../annotation_volumes//allen2022_colours.csv", + "counts_per_label_name": "../outputs/counts_per_allenID.csv" +} \ No newline at end of file