Skip to content

Commit

Permalink
ENH: Add graphical assistant for generating input for the crop of Cur…
Browse files Browse the repository at this point in the history
…vatureCorrection.
  • Loading branch information
jwboth committed Oct 9, 2023
1 parent 470cc6b commit 3d05508
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/darsia/assistants/crop_assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Modulde for crop assistant.
Main prupose of the assistant is to produce input arguments for the
'crop' option of CurvatureCorrection.
"""

import darsia


class CropAssistant(darsia.PointSelectionAssistant):
def __init__(self, img: darsia.Image, **kwargs) -> None:
super().__init__(img, **kwargs)

# Initialize containers
self._reset()

# Redefine pre-defined attributes
self.pts = None
"""Selected corners to define box after cropping."""

# Prepare further output
self.finalized_prompt_input = False
"""Flag controlling whether the user has entered the width and height."""

self.width = None
"""Identified width of the box."""

self.height = None
"""Identified height of the box."""

def _reset(self) -> None:
"""Reset list of points."""
super()._reset()

def __call__(self) -> dict:
"""Run the assistant.
Returns:
dict: configuration for the 'crop' option of CurvatureCorrection
"""
# Prompt a welcome message
print("Welcome to the CropAssistant!")

# Run point selection and check number of points is 4
super().__call__()
assert len(self.pts) == 4, "Wrong number of points selected"

# Ask user to enter width and height into prompt
if not self.finalized_prompt_input:
self.width = float(input("Enter width of box: "))
self.height = float(input("Enter height of box: "))
self.finalized_prompt_input = True

# Define a dictionary for input of the 'crop' option of CurvatureCorrection
config = self._define_config()

return config

def _define_config(self) -> dict:
"""Define a dictionary for input of the 'crop' option of CurvatureCorrection.
Returns:
dict: configuration for the 'crop' option of CurvatureCorrection
"""
return {
"crop": {
"width": self.width,
"height": self.height,
"pts_src": self.pts,
},
}

def _print_info(self) -> None:
"""Print out information about the assistant."""
print(self._define_config())

0 comments on commit 3d05508

Please sign in to comment.