diff --git a/PyNutil/counting_and_load.py b/PyNutil/counting_and_load.py index b48af03d8f920d1a43a2ea031b93ff52603a6613..6fd426ed8c871da02c6e458244a1633576fc3418 100644 --- a/PyNutil/counting_and_load.py +++ b/PyNutil/counting_and_load.py @@ -163,7 +163,7 @@ def flat_to_dataframe(flat_file, labelfile, rescaleXY=False): area_per_label = list(zip(unique_ids, counts)) # create a list of unique regions and pixel counts per region - df_area_per_label = pd.DataFrame(area_per_label, columns=["idx", "area_count"]) + df_area_per_label = pd.DataFrame(area_per_label, columns=["idx", "region_area"]) # create a pandas df with regions and pixel counts return(df_area_per_label) diff --git a/PyNutil/main.py b/PyNutil/main.py index 4cf3829be3224beefaec72137b19ab8126623400..bd9649e079ac7543f01fe08ba630e686d186d648 100644 --- a/PyNutil/main.py +++ b/PyNutil/main.py @@ -226,12 +226,31 @@ class PyNutil: # create the df for section report and all report # pixel_count_per_region returns a df with idx, pixel count, name and RGB. -# ra is region area list +# ra is region area list from # merge current_df onto ra (region_areas_list) based on idx column #(left means use only keys from left frame, preserve key order) current_df = ra.merge(current_df, on='idx', how='left') + + new_rows = [] + for index, row in current_df.iterrows(): + mask = self.atlas_labels["idx"] == row["idx"] + current_region_row = self.atlas_labels[mask] + current_region_name = current_region_row["name"].values + current_region_red = current_region_row["r"].values + current_region_green = current_region_row["g"].values + current_region_blue = current_region_row["b"].values + + row["name"] = current_region_name[0] + row["r"] = current_region_red[0] + row["g"] = current_region_green[0] + row["b"] = current_region_blue[0] + + new_rows.append(row) + + current_df_new = pd.DataFrame(new_rows) + ##Sharon. I would guess you should add the rgb and name adding code here - per_section_df.append(current_df) + per_section_df.append(current_df_new) prev_pl += pl prev_cl += cl