Commit 31b0b619 authored by Sean Fitzgibbon's avatar Sean Fitzgibbon
Browse files

Allow for repeat contours in neurolucida

parent d1a2884e
......@@ -66,7 +66,12 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
img = jp2.read(rlevel=rlevel)
# initial scaling based on boundng boxes
edge_crds = contour[boundary_key][:, :2] * [1, -1]
boundary_idx = np.where([f==boundary_key for f,_ in contour])[0]
if boundary_idx.size > 1:
raise RuntimeError(f'Repeated entries of boundary key in chart: {boundary_key}')
print(boundary_idx)
edge_crds = contour[boundary_idx[0]][1][:, :2] * [1, -1]
init = _init_scale(img, slide_res, edge_crds, verbose=True)
print(init)
print(
......@@ -95,9 +100,9 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
# apply opt-xfm to contours and cells and save
contour_xfm = {
k: _apply_xfm(opt, v[:, :2] * [1, -1]).tolist() for k, v in contour.items()
}
contour_xfm = [
(k, _apply_xfm(opt, v[:, :2] * [1, -1]).tolist()) for k, v in contour
]
if DO_PLOTS:
fig, ax = plt.subplots(figsize=(10, 10))
......@@ -105,7 +110,7 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
extent = np.array([0, img.shape[1], img.shape[0], 0]) * slide_res
ax.imshow(img, extent=extent)
for name, coords in contour_xfm.items():
for name, coords in contour_xfm:
coords = np.array(coords)
......
......@@ -180,14 +180,14 @@ def _flatten_subsection(subsection, _type, offset, parent):
def _to_data(sections):
cells = []
contour = {}
contour = []
xyz = []
for section in sections:
if section[0] == 'Asterisk': # Cell
cells.append( np.asarray(section[2],dtype=np.float64) )
else:
contour[section[0].replace('"','')] = np.asarray(section[1:],dtype=np.float64)
contour.append((section[0].replace('"',''), np.asarray(section[1:],dtype=np.float64)))
cells = np.asarray(cells)
......@@ -195,7 +195,7 @@ def _to_data(sections):
def read(file):
'''return a dict
'''return a list of tuples
'''
with open(file, encoding='utf-8', errors='replace') as fd:
......
Markdown is supported
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