diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..de288e1eab6a537caed290ce0fc5e70be7ae9dba --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.formatting.provider": "black" +} \ No newline at end of file diff --git a/PyNutil/generate_target_slice.py b/PyNutil/generate_target_slice.py new file mode 100644 index 0000000000000000000000000000000000000000..2968338a1d9b53d066c69b788e3a29cee226a0ac --- /dev/null +++ b/PyNutil/generate_target_slice.py @@ -0,0 +1,79 @@ +import numpy as np + + +def generate_target_slice(alignment, volume): + Ox, Oy, Oz, Ux, Uy, Uz, Vx, Vy, Vz = alignment + ##just for mouse for now + bounds = [455, 527, 319] + X_size = np.sqrt(np.sum(np.square((Ux, Uy, Uz)))) + Z_size = np.sqrt(np.sum(np.square((Vx, Vy, Vz)))) + print(X_size, Z_size) + X_size = np.round(X_size).astype(int) + Z_size = np.round(Z_size).astype(int) + # make this into a grid (0,0) to (320,456) + Uarange = np.arange(0, 1, 1 / X_size) + Varange = np.arange(0, 1, 1 / Z_size) + Ugrid, Vgrid = np.meshgrid(Uarange, Varange) + Ugrid_x = Ugrid * Ux + Ugrid_y = Ugrid * Uy + Ugrid_z = Ugrid * Uz + Vgrid_x = Vgrid * Vx + Vgrid_y = Vgrid * Vy + Vgrid_z = Vgrid * Vz + + X_Coords = (Ugrid_x + Vgrid_x).flatten() + Ox + Y_Coords = (Ugrid_y + Vgrid_y).flatten() + Oy + Z_Coords = (Ugrid_z + Vgrid_z).flatten() + Oz + + X_Coords = np.round(X_Coords).astype(int) + Y_Coords = np.round(Y_Coords).astype(int) + Z_Coords = np.round(Z_Coords).astype(int) + + out_bounds_Coords = ( + (X_Coords > bounds[0]) | (Y_Coords > bounds[1]) | (Z_Coords > bounds[2]) + ) + X_pad = X_Coords.copy() + Y_pad = Y_Coords.copy() + Z_pad = Z_Coords.copy() + + X_pad[out_bounds_Coords] = 0 + Y_pad[out_bounds_Coords] = 0 + Z_pad[out_bounds_Coords] = 0 + + regions = volume[X_pad, Y_pad, Z_pad] + ##this is a quick hack to solve rounding errors + C = len(regions) + compare = C - X_size * Z_size + if abs(compare) == X_size: + if compare > 0: + Z_size += 1 + if compare < 0: + Z_size -= 1 + elif abs(C - X_size * Z_size) == Z_size: + if compare > 0: + X_size += 1 + if compare < 0: + X_size -= 1 + elif abs(C - X_size * Z_size) == Z_size + X_size: + if compare > 0: + X_size += 1 + Z_size += 1 + if compare < 0: + X_size -= 1 + Z_size -= 1 + elif abs(C - X_size * Z_size) == Z_size - X_size: + if compare > 0: + X_size += 1 + Z_size -= 1 + if compare < 0: + X_size -= 1 + Z_size += 1 + elif abs(C - X_size * Z_size) == X_size - Z_size: + if compare > 0: + X_size -= 1 + Z_size += 1 + if compare < 0: + X_size += 1 + Z_size -= 1 + regions = regions.reshape((abs(Z_size), abs(X_size))) + return regions diff --git a/PyNutil/main.py b/PyNutil/main.py index 73eae5818911035deff9220fec8dc6604844e053..2a2ea71cd0216cec727d120277499d1b595ab4f4 100644 --- a/PyNutil/main.py +++ b/PyNutil/main.py @@ -5,6 +5,7 @@ from .counting_and_load import label_points, pixel_count_per_region import json import pandas as pd from datetime import datetime +import os class PyNutil: @@ -218,6 +219,9 @@ class PyNutil: If the pixel coordinates have not been extracted. """ + if not os.path.exists(output_folder): + os.makedirs(output_folder) + if not hasattr(self, "pixel_points"): raise ValueError("Please run get_coordinates before running save_analysis") diff --git a/annotation_volumes/annotation_25.nrrd b/annotation_volumes/annotation_25.nrrd new file mode 100644 index 0000000000000000000000000000000000000000..ed25a4b0234f72086d5f959a0b1b36f0126765f6 Binary files /dev/null and b/annotation_volumes/annotation_25.nrrd differ diff --git a/annotation_volumes/annotation_25_reoriented.nrrd b/annotation_volumes/annotation_25_reoriented.nrrd new file mode 100644 index 0000000000000000000000000000000000000000..c9fad7411a31bab6b4f35de3aaa0e7d5046a9c4c Binary files /dev/null and b/annotation_volumes/annotation_25_reoriented.nrrd differ diff --git a/workflows/calculate_objects_per_region.py b/workflows/calculate_objects_per_region.py new file mode 100644 index 0000000000000000000000000000000000000000..a72a549177842854e41d4e7e9a4c85ee1d717ae6 --- /dev/null +++ b/workflows/calculate_objects_per_region.py @@ -0,0 +1,12 @@ +import cv2 +from skimage import measure + + +# read the segmentation image +segmentation_path = "" +segmentation = cv2.imread(segmentation_path) +# apply get centroids and area function + +# try to label the coordinates + +# try to save the coordinates to a csv file