diff --git a/PyNutil/processing/coordinate_extraction.py b/PyNutil/processing/coordinate_extraction.py index 38c291f3a9a8d60dbecfec096a85fb979ddca55b..37e535853ee68545c411b74a42dbff6a30d434f0 100644 --- a/PyNutil/processing/coordinate_extraction.py +++ b/PyNutil/processing/coordinate_extraction.py @@ -389,7 +389,7 @@ def get_region_areas( atlas_map = load_image(flat_file_atlas,slice_dict["anchoring"], atlas_volume, triangulation, (seg_width, seg_height), atlas_labels) region_areas = flat_to_dataframe( - atlas_map, (seg_width, seg_height) + atlas_map, damage_mask, (seg_width, seg_height) ) return region_areas, atlas_map diff --git a/PyNutil/processing/counting_and_load.py b/PyNutil/processing/counting_and_load.py index f15ff366f67989c8d0a067b27b6e874c608cd360..c09dc67d23b1378b9883c9c10d2df214f050d62f 100644 --- a/PyNutil/processing/counting_and_load.py +++ b/PyNutil/processing/counting_and_load.py @@ -270,6 +270,7 @@ def warp_image(image, triangulation, rescaleXY): def flat_to_dataframe( image, + damage_mask, rescaleXY=None): """ Converts a flat file to a DataFrame. @@ -287,7 +288,16 @@ def flat_to_dataframe( np.array: array in shape of alignment XY scaled by rescaleXY with allen ID for each point """ scale_factor = calculate_scale_factor(image, rescaleXY) - df_area_per_label = count_pixels_per_label(image, scale_factor) + if damage_mask is not None: + damage_mask = cv2.resize(damage_mask.astype(np.uint8), (image.shape[::-1]), interpolation=cv2.INTER_NEAREST).astype(bool) + undamaged_df_area_per_label = count_pixels_per_label(image[damage_mask], scale_factor) + damaged_df_area_per_label = count_pixels_per_label(image[~damage_mask], scale_factor) + undamaged_df_area_per_label = undamaged_df_area_per_label.rename(columns={"region_area": "undamaged_region_area"}) + damaged_df_area_per_label = damaged_df_area_per_label.rename(columns={"region_area": "damaged_region_area"}) + df_area_per_label = pd.merge(undamaged_df_area_per_label, damaged_df_area_per_label, on='idx', how='outer').fillna(0) + df_area_per_label["region_area"] = df_area_per_label["undamaged_region_area"] + df_area_per_label["damaged_region_area"] + else: + df_area_per_label = count_pixels_per_label(image, scale_factor) return df_area_per_label diff --git a/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003.png b/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003.png index 7ff61a5947eca46caa8b304805a5210b93dbd5d7..260f98b911f9071cb51e7d5a47bd263866afae6b 100644 Binary files a/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003.png and b/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003.png differ diff --git a/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003_.png b/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003_.png deleted file mode 100644 index 260f98b911f9071cb51e7d5a47bd263866afae6b..0000000000000000000000000000000000000000 Binary files a/tests/test_data/nonlinear_allen_mouse/segmentations/test_s003_.png and /dev/null differ