Skip to content
Snippets Groups Projects
Commit 4936347d authored by Sharon Yates's avatar Sharon Yates
Browse files

def flat_to_dataframe

parent eabcdc17
No related branches found
No related tags found
No related merge requests found
...@@ -93,7 +93,7 @@ def folder_to_atlas_space( ...@@ -93,7 +93,7 @@ def folder_to_atlas_space(
object_cutoff=0, object_cutoff=0,
): ):
"""Apply Segmentation to atlas space to all segmentations in a folder.""" """Apply Segmentation to atlas space to all segmentations in a folder."""
"""Return pixel_points, centroids, points_len, centroids_len, segmentation_filenames, """
# This should be loaded above and passed as an argument # This should be loaded above and passed as an argument
slices = load_visualign_json(quint_alignment) slices = load_visualign_json(quint_alignment)
......
...@@ -117,7 +117,7 @@ def pixel_count_per_region( ...@@ -117,7 +117,7 @@ def pixel_count_per_region(
"""Read flat file and write into an np array""" """Read flat file and write into an np array"""
"""Read flat file, write into an np array, assign label file values, return array""" """Read flat file, write into an np array, assign label file values, return array"""
def flat_to_array(flat_file, labelfile): def flat_to_dataframe(flat_file, labelfile):
with open(flat_file, "rb") as f: with open(flat_file, "rb") as f:
# I don't know what b is, w and h are the width and height that we get from the # I don't know what b is, w and h are the width and height that we get from the
# flat file header # flat file header
...@@ -145,9 +145,9 @@ def flat_to_array(flat_file, labelfile): ...@@ -145,9 +145,9 @@ def flat_to_array(flat_file, labelfile):
values = image_arr[coordsx, coordsy] # assign x,y coords from image_array into values values = image_arr[coordsx, coordsy] # assign x,y coords from image_array into values
lbidx = labelfile["idx"].values lbidx = labelfile["idx"].values
allen_id_image = lbidx[values.astype(int)] allen_id_image = lbidx[values.astype(int)]
return allen_id_image #return allen_id_image
#def count_per_uniqueidx() #def count_per_uniqueidx()
"""count pixels for unique idx""" """count pixels for unique idx"""
unique_ids, counts = np.unique(allen_id_image, return_counts=True) unique_ids, counts = np.unique(allen_id_image, return_counts=True)
......
...@@ -6,27 +6,27 @@ import pandas as pd ...@@ -6,27 +6,27 @@ import pandas as pd
import numpy as np import numpy as np
#from read_and_write import flat_to_array, label_to_array #from read_and_write import flat_to_array, label_to_array
from counting_and_load import flat_to_array from counting_and_load import flat_to_dataframe
base = r"../test_data/tTA_2877_NOP_s037_atlasmap/2877_NOP_tTA_lacZ_Xgal_s037_nl.flat" base = r"../test_data/tTA_2877_NOP_s037_atlasmap/2877_NOP_tTA_lacZ_Xgal_s037_nl.flat"
label = r"../annotation_volumes\allen2017_colours.csv" label = r"../annotation_volumes\allen2017_colours.csv"
#image_arr = flat_to_array(base, label) #image_arr = flat_to_array(base, label)
plt.imshow(flat_to_array(base, label))
#plt.imshow(flat_to_array(base, label))
df_area_per_label = flat_to_dataframe(base, label)
"""count pixels in np array for unique idx, return pd df""" """count pixels in np array for unique idx, return pd df"""
unique_ids, counts = np.unique(allen_id_image, return_counts=True) #unique_ids, counts = np.unique(allen_id_image, return_counts=True)
area_per_label = list(zip(unique_ids, counts)) #area_per_label = list(zip(unique_ids, counts))
# create a list of unique regions and pixel counts per region # 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", "area_count"])
# create a pandas df with regions and pixel counts # create a pandas df with regions and pixel counts
"""add region name and colours corresponding to each idx into dataframe. """add region name and colours corresponding to each idx into dataframe.
This could be a separate function""" This could be a separate function"""
......
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