diff --git a/PyNutil/coordinate_extraction.py b/PyNutil/coordinate_extraction.py index 607d5da05f1bf8f65aae6a88cb0df7a434466784..f218125eb2490c8902cea25d7a2dca0b47b9f7c9 100644 --- a/PyNutil/coordinate_extraction.py +++ b/PyNutil/coordinate_extraction.py @@ -17,8 +17,8 @@ def getCentroidsAndArea(Segmentation, pixelCutOff=0): """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 """ - SegmentationBinary = ~np.all(Segmentation == 255, axis=2) - labels = measure.label(SegmentationBinary) + # SegmentationBinary = ~np.all(Segmentation == 255, axis=2) + labels = measure.label(Segmentation) # this finds all the objects in the image labelsInfo = measure.regionprops(labels) # remove objects that are less than pixelCutOff @@ -144,11 +144,6 @@ def SegmentationToAtlasSpace( """combines many functions to convert a segmentation to atlas space. It takes care of deformations""" 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": # remove the background from the segmentation SegmentationNoBackGround = Segmentation[~np.all(Segmentation == 255, axis=2)] @@ -157,7 +152,7 @@ def SegmentationToAtlasSpace( ) # remove background # currently only works for a single label pixelID = pixelID[0] - ID_pixels = findMatchingPixels(Segmentation, pixelID) + # transform pixels to registration space (the registered image and segmentation have different dimensions) SegHeight = Segmentation.shape[0] SegWidth = Segmentation.shape[1] @@ -166,8 +161,20 @@ def SegmentationToAtlasSpace( # this calculates reg/seg Yscale, Xscale = transformToRegistration(SegHeight, SegWidth, RegHeight, RegWidth) - # scale the seg coordinates to reg/seg - scaledY, scaledX = scalePositions(ID_pixels[0], ID_pixels[1], Yscale, Xscale) + 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 + 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 "markers" in slice: # this creates a triangulation using the reg width diff --git a/PyNutil/main.py b/PyNutil/main.py index 6334ab2db7a9db035e514ee45cf4a045f34fe83f..0179f90dd149236b5da4d0f9215e4e001d10b9c2 100644 --- a/PyNutil/main.py +++ b/PyNutil/main.py @@ -53,11 +53,11 @@ class PyNutil: startTime = datetime.now() self.atlas_volume = readAtlasVolume(atlas_root_path + current_atlas_path) 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"] print("loading atlas labels") 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"): if not hasattr(self, "atlas_volume"): @@ -90,7 +90,7 @@ class PyNutil: self.label_df = PixelCountPerRegion(labeled_points, self.atlas_labels) self.labeled_points = labeled_points - print("quantification complete") + print("quantification complete ✅") def save_analysis(self, output_folder): if not hasattr(self, "pixel_points"): @@ -113,4 +113,4 @@ class PyNutil: output_folder + "/pixels_meshview.json", self.atlas_labels, ) - print("analysis saved") + print("analysis saved ✅")