Project Setup

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 os import listdir
# from os.path import join, abspath, relpath
from pathlib import Path
from misalign.model.project import MISProjectJSON

Basic Setup

###
# Enter setup information
###
folder_path=Path("../../../example/project_a") # folder with images
misfile_name="demo-project_a-no_relations-calibrated.mis.json" # name for save file
#
calibration_filepath=Path("../../../example/project_a/scale_5x_1mm.miscal.json")
    # filepath to calibration file `.miscal.json`
# Important: If you do not have a calibration file then uncomment the next line
# calibration_filepath=None
#
file_ending=".jpg" # file extension
file_contains="" # file names must contain - i.e. "sample1-5x", "sample2", "10x", etc.
file_notcontains="" # file names must not contain - i.e. "calibration"
#TODO Change not contains to a list of strings to check against.
###
mis_filepath=folder_path.joinpath(misfile_name)
print(f"Save file filepath: {mis_filepath}")
file_paths=[x for x in folder_path.iterdir() if x.suffix==file_ending]
if file_contains != "":
    file_paths=[x for x in file_paths if file_contains in x]
if file_notcontains != "":
    file_paths=[x for x in file_paths if file_notcontains not in x]
print("\n  ".join(["Image files and filepaths:"]+[f"{fp.name}: {fp}" for fp in file_paths]))
filepath_dict={fp.name:fp for fp in file_paths}
if calibration_filepath is not None:
    print(f"Calibration file filepath: {calibration_filepath}")
Save file filepath: ../../../example/project_a/demo-project_a-no_relations-calibrated.mis.json
Image files and filepaths:
  image_a09.jpg: ../../../example/project_a/image_a09.jpg
  image_a02.jpg: ../../../example/project_a/image_a02.jpg
  image_a06.jpg: ../../../example/project_a/image_a06.jpg
  image_a07.jpg: ../../../example/project_a/image_a07.jpg
  image_a04.jpg: ../../../example/project_a/image_a04.jpg
  image_a10.jpg: ../../../example/project_a/image_a10.jpg
  image_a05.jpg: ../../../example/project_a/image_a05.jpg
  image_a08.jpg: ../../../example/project_a/image_a08.jpg
  image_a01.jpg: ../../../example/project_a/image_a01.jpg
  image_a03.jpg: ../../../example/project_a/image_a03.jpg
Calibration file filepath: ../../../example/project_a/scale_5x_1mm.miscal.json
mis_project=MISProjectJSON.build(image_filepaths=file_paths,calibration_filepath=calibration_filepath,mis_filepath=mis_filepath)
print(mis_project)
A misalign project with:
Images:
    image_a09.jpg
    image_a02.jpg
    image_a06.jpg
    image_a07.jpg
    image_a04.jpg
    image_a10.jpg
    image_a05.jpg
    image_a08.jpg
    image_a01.jpg
    image_a03.jpg
Relations:

Calibration:
    pixel : 600
    length : 1
    length_unit : mm
Project Path:
    ../../../example/project_a/demo-project_a-no_relations-calibrated.mis.json

Note

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

mis_project.save(mis_filepath)

Advanced Setups

Image Sets

###
# Enter setup information
###
folder_path=Path("../../../example/project_a/") # folder with images
misfile_names=["demo-set_a1a.mis.json","demo-set_a1b.mis.json"] # name for save file
#
file_ending=".jpg" # file extension
file_contains="" # file names must contain - i.e. "sample1-5x", "sample2", "10x", etc.
file_notcontains="" # file names must not contain - i.e. "calibration"
###
mis_filepaths=[folder_path.joinpath(x) for x in misfile_names]
mis_dict={mn:mp for mn,mp in zip(misfile_names,mis_filepaths)}
print("\n  ".join(["Save files and filepaths: "]+[f"{mn}: {mp}" for mn,mp in zip(misfile_names,mis_filepaths)]))
file_paths=[x for x in folder_path.iterdir() if x.suffix==file_ending]
if file_contains != "":
    file_paths=[x for x in file_paths if file_contains in x]
if file_notcontains != "":
    file_paths=[x for x in file_paths if file_notcontains not in x]
print("\n  ".join(["Image index, file names, and filepaths:"]+[f"{i} - {fp.name}: {fp}" for i,fp in enumerate(file_paths)]))
# user selected image sets using start and end index
image_sets={
    "demo-set_a1a.mis.json":(0,4),
    "demo-set_a1b.mis.json":(5,9),
}
for key,value in image_sets.items():
    print(key,[x.name for x in file_paths[value[0]:value[1]+1]])
for key,value in image_sets.items():
    mis_fp=mis_dict[key]
    print(mis_fp,"\n  ",[x.name for x in file_paths[value[0]:value[1]+1]])
    mis_project=MISProjectJSON.build(image_filepaths=file_paths[value[0]:value[1]+1],mis_filepath=mis_fp)
    mis_project.save(mis_fp)