diff --git a/ProjectSegmentation3D_vec.py b/PyNutil.py similarity index 85% rename from ProjectSegmentation3D_vec.py rename to PyNutil.py index 885c97ada7203b8812bbe9aabb945d98aa77d532..8d4510b9722f43dd8a2acb6505826bd5680ff4df 100644 --- a/ProjectSegmentation3D_vec.py +++ b/PyNutil.py @@ -26,7 +26,7 @@ def assignPointsToRegions(points, regionVolume): return regionDict -def transformToRegistration( SegHeight, SegWidth, RegHeight, RegWidth): +def transformToRegistration(SegHeight, SegWidth, RegHeight, RegWidth): Yscale = RegHeight/SegHeight Xscale = RegWidth/SegWidth return Yscale,Xscale @@ -97,22 +97,6 @@ def SegmentationToAtlasSpace(slice, SegmentationPath, pixelID='auto', nonLinear= # points = points.reshape(-1) return points -# def applyTransformationToPoints(ID_pixels, slice,SegHeight, SegWidth, nonLinear=True): -# RegHeight = slice["height"] -# RegWidth = slice["width"] -# #this calculates reg/seg -# Yscale , Xscale = transformToRegistration(SegHeight,SegWidth, RegHeight,RegWidth) -# #this creates a triangulation using the reg width -# triangulation = triangulate(RegWidth, RegHeight, slice["markers"]) -# #scale the seg coordinates to reg/seg -# scaledY,scaledX = scalePositions(ID_pixels[0], ID_pixels[1], Yscale, Xscale) -# if nonLinear: -# newX, newY = transform_vec(triangulation, scaledX, scaledY) -# else: -# newX, newY = scaledX, scaledY -# #scale U by Uxyz/RegWidth and V by Vxyz/RegHeight -# points = transformToAtlasSpace(slice['anchoring'], newY, newX, RegHeight, RegWidth) -# return points def FolderToAtlasSpace(folder, QUINT_alignment, pixelID=[0, 0, 0], nonLinear=True): slices = loadVisuAlignJson(QUINT_alignment) diff --git a/basic_workflow.py b/basic_workflow.py new file mode 100644 index 0000000000000000000000000000000000000000..933f64fe2846c934e419cfde7e0c0ae054a89044 --- /dev/null +++ b/basic_workflow.py @@ -0,0 +1,20 @@ +#pandas is used for working with csv files +import pandas as pd +#nrrd just lets us open nrrd files +import nrrd +#import our function for converting a folder of segmentations to points +from PyNutil import FolderToAtlasSpace + + + +#now we can use our function to convert the folder of segmentations to points +points = FolderToAtlasSpace("test_data/oneSection15/", "test_data/C68_nonlinear.json", pixelID=[255, 0, 255], nonLinear=True) + +#first we need to find the label file for the volume +label_path = "annotation_volumes//allen2022_colours.csv" +#then the path to the volume +volume_path = "annotation_volumes//annotation_10.nrrd" +#read the label file +label_df = pd.read_csv(label_path) +#read the annotation volume, it also has a header but we don't need it +data, header = nrrd.read(volume_path) \ No newline at end of file diff --git a/reformat_allen_label.py b/reformat_allen_label.py new file mode 100644 index 0000000000000000000000000000000000000000..9c2bd8b064959de8e654eaf191a451f5592dca34 --- /dev/null +++ b/reformat_allen_label.py @@ -0,0 +1,11 @@ +import pandas as pd +#open colour txt file +path = "itksnap_label_description.txt" + + +# use " " as separator +#set column names +df = pd.read_csv(path, sep=" ", header=None, names=["id", "r", "g", "b", "1a", "1b", "1c", "name"]) +df[["name", "allenID"]] = df["name"].str.split(' - ', expand=True) +df.to_csv("allen2022_colours.csv", index=False) +