Commit 410f89aa authored by Sean Fitzgibbon's avatar Sean Fitzgibbon
Browse files

changed affine to rigid

parent dfcb8b76
......@@ -32,16 +32,20 @@ import numpy as np
import matplotlib.pyplot as plt
def register_chart_to_slide(chart, slide, slide_res, out, config=None):
def register_chart_to_slide(chart, slide, slide_res, out, boundary_key=None, config=None):
if config is None:
config = util.get_resource("chart.yaml")
with open(config, "r") as f:
config = yaml.load(f)
config = yaml.load(f, Loader=yaml.FullLoader)
rlevel = config["slide"]["resolution_level"]
boundary_key = config["chart"]["boundary_key"]
if boundary_key is None:
boundary_key = config["chart"]["boundary_key"]
print(boundary_key)
# set global variables required for summary plots
plots = config["general"]["plots"]
......@@ -74,9 +78,9 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
edge_crds = contour[boundary_idx[0]][1][:, :2] * [1, -1]
init = _init_scale(img, slide_res, edge_crds, verbose=True)
print(init)
print(
f"Rotation: {init.rotation}, Translation: {init.translation}, Scale: {init.scale}, Shear: {init.shear}"
)
# print(
# f"Rotation: {init.rotation}, Translation: {init.translation}, Scale: {init.scale}, Shear: {init.shear}"
# )
# calculate normal line to boundary points
xfm_edge_coords = _apply_xfm(init, edge_crds)
......@@ -88,12 +92,12 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
)
# estimate opimised affine transform
opt = transform.AffineTransform()
opt = transform.SimilarityTransform()
opt.estimate(edge_crds, refined_edge_coords)
print(opt)
print(
f"Rotation:\t{opt.rotation}\nTranslation:\t{opt.translation}\nScale:\t\t{list(opt.scale)}\nShear:\t\t{opt.shear}"
)
# print(
# f"Rotation:\t{opt.rotation}\nTranslation:\t{opt.translation}\nScale:\t\t{list(opt.scale)}\nShear:\t\t{opt.shear}"
# )
# save opt transform
np.savetxt(f"{out}/chart-to-image.xfm", opt.params)
......@@ -140,9 +144,9 @@ def register_chart_to_slide(chart, slide, slide_res, out, config=None):
json.dump(contour_xfm, fp, indent=4)
if cells.size > 0:
cells_xfm = _apply_xfm(cells[:, :2] * [1, -1])
cells_xfm = _apply_xfm(opt, cells[:, :2] * [1, -1])
with open(f"{out}/cells.json", "w") as fp:
json.dump(cells_xfm, fp, indent=4)
json.dump(cells_xfm.tolist(), fp, indent=4)
def _refine_edge_coord(img, img_res, edge_coords, normals):
......@@ -360,7 +364,7 @@ def _init_scale(img, img_resolution, crd, verbose=False):
src = np.array(crd_p["bbox"])[idx]
dest = np.array(img_p["bbox"])[idx]
a = transform.AffineTransform()
a = transform.SimilarityTransform()
a.estimate(src, dest)
return a
......
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