diff --git a/PyNutil.py b/PyNutil.py index 8d4510b9722f43dd8a2acb6505826bd5680ff4df..5daaf2d5d7a3bba662f5cdceaa217fb703c53d1b 100644 --- a/PyNutil.py +++ b/PyNutil.py @@ -130,4 +130,19 @@ def WritePoints(pointsDict, filename, infoFile): ] #write meshview json with open(filename, "w") as f: - json.dump(meshview, f) \ No newline at end of file + json.dump(meshview, f) + + +def labelPoints(points, label_volume, scale_factor=1): + #first convert the points to 3 columns + points = np.reshape(points, (-1,3)) + #scale the points + points = points * scale_factor + #round the points to the nearest whole number + points = np.round(points).astype(int) + x = points[:,0] + y = points[:,1] + z = points[:,2] + #get the label value for each point + labels = label_volume[x,y,z] + return labels diff --git a/annotation_volumes/annotation_10_reoriented.nrrd b/annotation_volumes/annotation_10_reoriented.nrrd new file mode 100644 index 0000000000000000000000000000000000000000..9ea83344cd6d3fa962c1e6af77ed68d8608885dd Binary files /dev/null and b/annotation_volumes/annotation_10_reoriented.nrrd differ diff --git a/basic_workflow.py b/basic_workflow.py index 933f64fe2846c934e419cfde7e0c0ae054a89044..be8db61d807cf0e3ea2a8a0a977e8dbb9feb8d86 100644 --- a/basic_workflow.py +++ b/basic_workflow.py @@ -3,18 +3,18 @@ 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 +from PyNutil import FolderToAtlasSpace, labelPoints #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" +volume_path = "annotation_volumes//annotation_10_reoriented.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 +data, header = nrrd.read(volume_path) +#now we can get the labels for each point diff --git a/reformat_allen_label.py b/scripts/reformat_allen_label.py similarity index 100% rename from reformat_allen_label.py rename to scripts/reformat_allen_label.py diff --git a/scripts/reorient_allen_volume.py b/scripts/reorient_allen_volume.py new file mode 100644 index 0000000000000000000000000000000000000000..e5bbf128f8152b4b7df22fa78c58add4dbeb469e --- /dev/null +++ b/scripts/reorient_allen_volume.py @@ -0,0 +1,14 @@ +""" +This script was needed to reorient the Allen Volume to match the +orientation of meshview coordinates. +""" + +import nrrd +import numpy as np +data, header = nrrd.read('../annotation_volumes/annotation_10.nrrd') +# change the order of the axes +data = np.transpose(data, (2,0,1)) +# flip two of the axes +data = data[:, ::-1, ::-1] +# write the new volume +nrrd.write('../annotation_volumes/annotation_10_reoriented.nrrd', data, header=header) diff --git a/testMemoVec.py b/testMemoVec.py index 51335cf3fb19925e885e4710197fdcbfef72b3b1..21207e3f9c8bfb31157be1608f46a258b6d0fbab 100644 --- a/testMemoVec.py +++ b/testMemoVec.py @@ -2,11 +2,24 @@ import time startTime = time.time() import numpy as np +from VisuAlignWarpVec import triangulate, forwardtransform_vec, forwardtransform import json from tqdm import tqdm +import matplotlib.pyplot as plt import matplotlib matplotlib.use('TkAgg') +from ProjectSegmentation3D_vec import FolderToAtlasSpace, getCentroidsAndArea, assignPointsToRegions + +import cv2 + +# Segmentation = cv2.imread("ext-d000033_PVMouseExtraction_pub-Nutil_Quantifier_analysis-81264-Input_dir/ext-d000009_PVMouse_81264_Samp1_resize15__s013_thumbnail_FinalSegmentation.png") +#count the number of isolated segments +# Segmentation[~np.all(Segmentation==255, axis=2)] = 0 + +# centroids, area = getCentroidsAndArea(Segmentation, 4) + +