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

Flat to array fix

parent 8641963b
No related branches found
No related tags found
No related merge requests found
......@@ -3,16 +3,17 @@ import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from read_and_write import FlattoArray
from read_and_write import FlattoArray, LabeltoArray
base= r"../test_data/ttA_2877_NOP_atlasmaps/2877_NOP_tTA_lacZ_Xgal_s037_nl.flat"
label = r"../annotation_volumes\allen2017_colours.csv"
image_arr = FlattoArray(base)
plt.imshow(FlattoArray(base))
"""assign label file values into image array"""
labelfile = pd.read_csv("../annotation_volumes/allen2017_colours.csv")
labelfile = pd.read_csv(r"../annotation_volumes\allen2017_colours.csv")
allen_id_image = np.zeros((h,w)) # create an empty image array
coordsy, coordsx = np.meshgrid(list(range(w)), list(range(h)))
values = image_arr[coordsx, coordsy] # assign x,y coords from image_array into values
......
......@@ -56,7 +56,7 @@ def SaveDataframeasCSV(df_to_save, output_csv):
def FlattoArray(flatfile):
"""Read flat file and write into an np array"""
"""Read flat file and write into an np array, return array"""
with open(flatfile,"rb") as f:
#i dont know what b is, w and h are the width and height that we get from the
#flat file header
......@@ -75,4 +75,16 @@ def FlattoArray(flatfile):
image[y,x] = imagedata[x+y*w]
image_arr = np.array(image)
return image_arr
\ No newline at end of file
return image_arr
def LabeltoArray(label_path, image_array):
"""assign label file values into image array, return array"""
labelfile = pd.read_csv(label_path)
allen_id_image = np.zeros((h,w)) # create an empty image array
coordsy, coordsx = np.meshgrid(list(range(w)), list(range(h)))
values = image_array[coordsx, coordsy] # assign x,y coords from image_array into values
lbidx = labelfile['idx'].values
allen_id_image = lbidx[values.astype(int)] # assign allen IDs into image array
return allen_id_image
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