Commit b67fd752 authored by Sean Fitzgibbon's avatar Sean Fitzgibbon
Browse files

added left or right justification

parent bda1c201
......@@ -64,7 +64,7 @@ def estimate_field(img):
def register_chart_to_slide(chart, slide, slide_res, outdir, boundary_key=None, config=None, do_plots=None):
def register_chart_to_slide(chart, slide, slide_res, outdir, boundary_key=None, config=None, do_plots=None, justify=None):
if config is None:
config = util.get_resource("chart.yaml")
......@@ -113,7 +113,7 @@ def register_chart_to_slide(chart, slide, slide_res, outdir, boundary_key=None,
# initial alignment based on boundng boxes
init_xfm, img_props, coord_props = init_scale(img, slide_res, edge_crds_cat)
init_xfm, img_props, coord_props = init_scale(img, slide_res, edge_crds_cat, justify=justify)
# print(init_xfm)
tr_x, tr_y = init_xfm.translation
......@@ -325,8 +325,8 @@ def refine_edge_coord(img, img_res, edge_coords, xfm_init):
line_x = np.round(line_x / img_res).astype(int)
line_y = np.round(line_y / img_res).astype(int)
line_int = brainmask[line_y, line_x]
y, x = brainmask.shape
line_int = brainmask[np.clip(line_y, 0, y-1), np.clip(line_x, 0, x-1)]
# exlude constant rows
constant_idx = np.all(line_int == line_int[:, 0][:, np.newaxis], axis=1)
......@@ -395,7 +395,7 @@ def point_props(pnts):
def init_scale(img, img_resolution, crd, tol=0.05):
def init_scale(img, img_resolution, crd, tol=0.05, justify=None):
img_p = image_props(img, img_resolution)
crd_p = point_props(crd)
......@@ -403,29 +403,29 @@ def init_scale(img, img_resolution, crd, tol=0.05):
# print(img_p)
# print(crd_p)
# justify='right'
# if justify=='right':
if justify=='right':
# bbox = img_p['bbox']
# h, w = img_p['shape']
print(f'justify chart bbox to {justify} in image bbox')
# scale_factor = crd_p['aspect_ratio'] / img_p['aspect_ratio']
bbox = img_p['bbox']
h, w = img_p['shape']
# new_w = w * scale_factor
# bbox[1] += (w - new_w)
# centroid = (
# (bbox[0] + bbox[2]) / 2,
# (bbox[1] + bbox[3]) / 2,
# )
scale_factor = crd_p['aspect_ratio'] / img_p['aspect_ratio']
# img_p = {
# "bbox": bbox,
# "bbox_centroid": centroid,
# "shape": (bbox[2] - bbox[0], bbox[3] - bbox[1]),
# "aspect_ratio": (bbox[3] - bbox[1]) / (bbox[2] - bbox[0]),
new_w = w * scale_factor
bbox[1] += (w - new_w)
centroid = (
(bbox[0] + bbox[2]) / 2,
(bbox[1] + bbox[3]) / 2,
)
# }
img_p = {
"bbox": bbox,
"bbox_centroid": centroid,
"shape": (bbox[2] - bbox[0], bbox[3] - bbox[1]),
"aspect_ratio": (bbox[3] - bbox[1]) / (bbox[2] - bbox[0]),
"mask": img_p['mask'],
}
# print(img_p)
# print(crd_p)
......
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