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

added emoji

parent 1e51888c
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,8 @@ def getCentroidsAndArea(Segmentation, pixelCutOff=0): ...@@ -17,8 +17,8 @@ def getCentroidsAndArea(Segmentation, pixelCutOff=0):
"""this function returns the center coordinate of each object in the segmentation. """this function returns the center coordinate of each object in the segmentation.
You can set a pixelCutOff to remove objects that are smaller than that number of pixels You can set a pixelCutOff to remove objects that are smaller than that number of pixels
""" """
SegmentationBinary = ~np.all(Segmentation == 255, axis=2) # SegmentationBinary = ~np.all(Segmentation == 255, axis=2)
labels = measure.label(SegmentationBinary) labels = measure.label(Segmentation)
# this finds all the objects in the image # this finds all the objects in the image
labelsInfo = measure.regionprops(labels) labelsInfo = measure.regionprops(labels)
# remove objects that are less than pixelCutOff # remove objects that are less than pixelCutOff
...@@ -144,11 +144,6 @@ def SegmentationToAtlasSpace( ...@@ -144,11 +144,6 @@ def SegmentationToAtlasSpace(
"""combines many functions to convert a segmentation to atlas space. It takes care """combines many functions to convert a segmentation to atlas space. It takes care
of deformations""" of deformations"""
Segmentation = cv2.imread(SegmentationPath) Segmentation = cv2.imread(SegmentationPath)
if method in ["per_object", "all"]:
# this function returns the centroids, area and coordinates of all the objects in the segmentation
# right now we only use centroids
centroids, area, coords = getCentroidsAndArea(Segmentation, pixelCutOff=0)
print("number of objects: ", len(centroids))
if pixelID == "auto": if pixelID == "auto":
# remove the background from the segmentation # remove the background from the segmentation
SegmentationNoBackGround = Segmentation[~np.all(Segmentation == 255, axis=2)] SegmentationNoBackGround = Segmentation[~np.all(Segmentation == 255, axis=2)]
...@@ -157,7 +152,7 @@ def SegmentationToAtlasSpace( ...@@ -157,7 +152,7 @@ def SegmentationToAtlasSpace(
) # remove background ) # remove background
# currently only works for a single label # currently only works for a single label
pixelID = pixelID[0] pixelID = pixelID[0]
ID_pixels = findMatchingPixels(Segmentation, pixelID)
# transform pixels to registration space (the registered image and segmentation have different dimensions) # transform pixels to registration space (the registered image and segmentation have different dimensions)
SegHeight = Segmentation.shape[0] SegHeight = Segmentation.shape[0]
SegWidth = Segmentation.shape[1] SegWidth = Segmentation.shape[1]
...@@ -166,8 +161,20 @@ def SegmentationToAtlasSpace( ...@@ -166,8 +161,20 @@ def SegmentationToAtlasSpace(
# this calculates reg/seg # this calculates reg/seg
Yscale, Xscale = transformToRegistration(SegHeight, SegWidth, RegHeight, RegWidth) Yscale, Xscale = transformToRegistration(SegHeight, SegWidth, RegHeight, RegWidth)
# scale the seg coordinates to reg/seg if method in ["per_object", "all"]:
scaledY, scaledX = scalePositions(ID_pixels[0], ID_pixels[1], Yscale, Xscale) # this function returns the centroids, area and coordinates of all the objects in the segmentation
# right now we only use centroids
binary_seg = Segmentation == pixelID
binary_seg = np.all(binary_seg, axis=2)
centroids, area, coords = getCentroidsAndArea(binary_seg, pixelCutOff=0)
print("number of objects: ", len(centroids))
# print(centroids)
if method in ["per_pixel", "all"]:
ID_pixels = findMatchingPixels(Segmentation, pixelID)
# scale the seg coordinates to reg/seg
scaledY, scaledX = scalePositions(ID_pixels[0], ID_pixels[1], Yscale, Xscale)
if nonLinear: if nonLinear:
if "markers" in slice: if "markers" in slice:
# this creates a triangulation using the reg width # this creates a triangulation using the reg width
......
...@@ -53,11 +53,11 @@ class PyNutil: ...@@ -53,11 +53,11 @@ class PyNutil:
startTime = datetime.now() startTime = datetime.now()
self.atlas_volume = readAtlasVolume(atlas_root_path + current_atlas_path) self.atlas_volume = readAtlasVolume(atlas_root_path + current_atlas_path)
time_taken = datetime.now() - startTime time_taken = datetime.now() - startTime
print(f"atlas volume loaded in: {time_taken}") print(f"atlas volume loaded in: {time_taken}")
atlas_label_path = self.config["annotation_volumes"][self.atlas]["labels"] atlas_label_path = self.config["annotation_volumes"][self.atlas]["labels"]
print("loading atlas labels") print("loading atlas labels")
self.atlas_labels = pd.read_csv(atlas_root_path + atlas_label_path) self.atlas_labels = pd.read_csv(atlas_root_path + atlas_label_path)
print("atlas labels loaded") print("atlas labels loaded")
def get_coordinates(self, nonLinear=True, method="all"): def get_coordinates(self, nonLinear=True, method="all"):
if not hasattr(self, "atlas_volume"): if not hasattr(self, "atlas_volume"):
...@@ -90,7 +90,7 @@ class PyNutil: ...@@ -90,7 +90,7 @@ class PyNutil:
self.label_df = PixelCountPerRegion(labeled_points, self.atlas_labels) self.label_df = PixelCountPerRegion(labeled_points, self.atlas_labels)
self.labeled_points = labeled_points self.labeled_points = labeled_points
print("quantification complete") print("quantification complete")
def save_analysis(self, output_folder): def save_analysis(self, output_folder):
if not hasattr(self, "pixel_points"): if not hasattr(self, "pixel_points"):
...@@ -113,4 +113,4 @@ class PyNutil: ...@@ -113,4 +113,4 @@ class PyNutil:
output_folder + "/pixels_meshview.json", output_folder + "/pixels_meshview.json",
self.atlas_labels, self.atlas_labels,
) )
print("analysis saved") print("analysis saved")
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