Align Images

Note

This notebook is modified from how it appears in the ‘notebooks’ directory so it can render properly in the documentation. Primarily, this includes changed paths and mocked user interactions.

Imports

from misalign.model.project import MISProjectJSON
from misalign.alignment.interactive_manual import IMRControls

Basic Alignment

mis_filepath="../../../example/project_a/project_a-no_relations-calibrated.mis.json"
mis_project=MISProjectJSON.load(mis_filepath)
mis_project.find_image_paths(mis_filepath,update=True)
print(mis_project)
A misalign project with:
Images:
    image_a01.jpg
    image_a02.jpg
    image_a03.jpg
    image_a04.jpg
    image_a05.jpg
    image_a06.jpg
    image_a07.jpg
    image_a08.jpg
    image_a09.jpg
    image_a10.jpg
Relations:

Calibration:
    pixel : 600
    length : 1
    length_unit : mm
Project Path:
    ../../../example/project_a/project_a-no_relations-calibrated.mis.json
%matplotlib widget
imrc=IMRControls(mis_project)

### Code used to simulate user-input for documentation generation. ###
# Replaces a user selecting matching points on the calibration image.
class mock_event:
    def __init__(self, button, xdata, ydata):
        self.button = button
        self.xdata = xdata
        self.ydata = ydata
imrc.imr._relate_callback(mock_event(button=1, xdata=1325, ydata=1150))
imrc.imr._relate_callback(mock_event(button=1, xdata=1335, ydata=1260))
imrc.imr._relate_callback(mock_event(button=1, xdata=570, ydata=1170))
imrc.imr._relate_callback(mock_event(button=1, xdata=580, ydata=1280))
imrc.imr._relate_callback(mock_event(button=1, xdata=1080, ydata=1100))
imrc.imr._relate_callback(mock_event(button=1, xdata=1090, ydata=1210))
imrc._click_resolve('')
from IPython.display import clear_output,display
from matplotlib import pyplot as plt
clear_output()
display(imrc._full)
plt.show()
### End ###

Note

No further cells are executed in this notebook in the documentation.

# retrieve project with updated image relations from imrc
mis_project=imrc.get_mis()
print(mis_project)
# save updated mis project with image relations
mis_filepath="../../../example/project_a/demo-project_a-relations-calibrated.mis.json"
mis_project.save(mis_filepath)  # ty:ignore[unresolved-attribute]