'''Calculate image and contour bounding boxes, then estimate the transform (xfm) based on bounding box corners.'''
'''
Calculate the transform (xfm) based on bounding box corners
Args:
image: the image to be transformed
image_resolution: The resolution of the image.
contour: the contour to be transformed
tol: tolerance for aspect ratio mismatch between slide and contour
justify: str
Returns:
the transform (xfm), the image properties (image_p) and the contour properties (contour_p).
'''
brainmask=segment_foreground(image)
image_p=image_props(brainmask,image_resolution)
contour_p=point_props(contour)
# If the aspect-ratio of the image and contour bounding boxes are not equal it typically means that the image is bilateral whilst the contour is lateralised.
# Thust the contour bbox should left or right justified within the image bbox.