Skip to content
Snippets Groups Projects
Commit 1ff2a5a5 authored by Harry Carey's avatar Harry Carey
Browse files

fixed several issues

parent b1517a47
No related branches found
No related tags found
No related merge requests found
from .main import PyNutil
from .main import PyNutil
\ No newline at end of file
import numpy as np
import pandas as pd
import json
from .read_and_write import load_visualign_json
from .counting_and_load import label_points, flat_to_dataframe
from .counting_and_load import flat_to_dataframe
from .visualign_deformations import triangulate, transform_vec
from glob import glob
from tqdm import tqdm
import cv2
from skimage import measure
import threading
......@@ -210,12 +208,23 @@ def folder_to_atlas_space(
[t.join() for t in threads]
# Flatten points_list
points_len = [len(points) if points is not None else 0 for points in points_list]
points_len = [
len(points) if None not in points else 0 for points in points_list
]
centroids_len = [
len(centroids) if centroids is not None else 0 for centroids in centroids_list
]
points = np.concatenate(points_list)
centroids = np.concatenate(centroids_list)
len(centroids) if None not in centroids else 0 for centroids in centroids_list
]
points_list = [points for points in points_list if None not in points]
centroids_list = [centroids for centroids in centroids_list if None not in centroids]
if len(points_list) == 0:
points = np.array([])
else:
points = np.concatenate(points_list)
if len(centroids_list) == 0:
centroids = np.array([])
else:
centroids = np.concatenate(centroids_list)
return (
np.array(points),
......@@ -346,9 +355,7 @@ def segmentation_to_atlas_space(
else:
centroids = np.array([])
print(
f"Finished and points len is: {len(points)} and centroids len is: {len(centroids)}"
)
points_list[index] = np.array(points)
centroids_list[index] = np.array(centroids)
region_areas_list[index] = region_areas
......
import numpy as np
import pandas as pd
import struct
import matplotlib.pyplot as plt
import os
import nrrd
import cv2
from .generate_target_slice import generate_target_slice
......
"""Create workflow for calculating load based on atlas maps and segmentations"""
import struct
import matplotlib.pyplot as plt
import pandas as pd
import cv2
import numpy as np
# from read_and_write import flat_to_array, label_to_array
from counting_and_load import flat_to_dataframe
......
......@@ -161,7 +161,7 @@ class PyNutil:
raise ValueError(
f"method {method} not recognised, valid methods are: per_pixel, per_object, or all"
)
print("extracting coordinates")
print("extracting coordinates with method:", method)
(
pixel_points,
centroids,
......@@ -188,6 +188,7 @@ class PyNutil:
self.centroids_len = centroids_len
self.segmentation_filenames = segmentation_filenames
self.region_areas_list = region_areas_list
self.method = method
def quantify_coordinates(self):
"""Quantifies the pixel coordinates by region.
......@@ -205,11 +206,11 @@ class PyNutil:
print("quantifying coordinates")
labeled_points_centroids = None
labeled_points = None
if hasattr(self, "centroids"):
if self.method == "per_object" or self.method == "all":
labeled_points_centroids = label_points(
self.centroids, self.atlas_volume, scale_factor=1
)
if hasattr(self, "pixel_points"):
if self.method == "per_pixel" or self.method == "all":
labeled_points = label_points(
self.pixel_points, self.atlas_volume, scale_factor=1
)
......@@ -224,9 +225,9 @@ class PyNutil:
for pl, cl, ra in zip(
self.points_len, self.centroids_len, self.region_areas_list
):
if hasattr(self, "centroids"):
if self.method == "per_object" or self.method == "all":
current_centroids = labeled_points_centroids[prev_cl : prev_cl + cl]
if hasattr(self, "pixel_points"):
if self.method == "per_pixel" or self.method == "all":
current_points = labeled_points[prev_pl : prev_pl + pl]
current_df = pixel_count_per_region(
current_points, current_centroids, self.atlas_labels
......@@ -341,14 +342,14 @@ class PyNutil:
na_rep="",
index=False,
)
if hasattr(self, "pixel_points"):
if self.method == "per_pixel" or self.method == "all":
write_points_to_meshview(
self.pixel_points[prev_pl : pl + prev_pl],
self.labeled_points[prev_pl : pl + prev_pl],
f"{output_folder}/per_section_meshview/{split_fn}_pixels.json",
self.atlas_labels,
)
if hasattr(self, "centroids"):
if self.method == "per_object" or self.method == "all":
write_points_to_meshview(
self.centroids[prev_cl : cl + prev_cl],
self.labeled_points_centroids[prev_cl : cl + prev_cl],
......@@ -358,14 +359,14 @@ class PyNutil:
prev_cl += cl
prev_pl += pl
if hasattr(self, "pixel_points"):
if self.method == "per_pixel" or self.method == "all":
write_points_to_meshview(
self.pixel_points,
self.labeled_points,
f"{output_folder}/whole_series_meshview/pixels_meshview.json",
self.atlas_labels,
)
if hasattr(self, "centroids"):
if self.method == "per_object" or self.method == "all":
write_points_to_meshview(
self.centroids,
self.labeled_points_centroids,
......
from . import *
from . import *
\ No newline at end of file
import json
from pathlib import Path
import os
def load_config() -> dict:
......
......@@ -2,6 +2,7 @@ import math, re
def propagate(arr):
arr = arr.copy()
for slice in arr:
if "nr" not in slice:
slice["nr"] = int(re.search(r"_s(\d+)", slice["filename"]).group(1))
......@@ -12,7 +13,7 @@ def propagate(arr):
count = 0
for slice in arr:
if "anchoring" in slice:
a = slice["anchoring"].copy()
a = slice["anchoring"]
for i in range(3):
a[i] += (a[i + 3] + a[i + 6]) / 2
a.extend(
......
......@@ -2,7 +2,6 @@ import json
import numpy as np
import struct
import pandas as pd
import matplotlib.pyplot as plt
import os
import nrrd
import re
......
"""This code was written by Gergely Csucs and Rembrandt Bakker"""
import numpy as np
from scipy.spatial import Delaunay
def triangulate(w, h, markers):
......
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