-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add graphical assistant for generating input for the crop of Cur…
…vatureCorrection.
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |