diff --git a/src/darsia/assistants/crop_assistant.py b/src/darsia/assistants/crop_assistant.py index 931dcb2e..d07ff479 100644 --- a/src/darsia/assistants/crop_assistant.py +++ b/src/darsia/assistants/crop_assistant.py @@ -37,10 +37,10 @@ def __init__(self, img: darsia.Image, **kwargs) -> None: self.finalized_prompt_input = False """Flag controlling whether the user has entered the width and height.""" - self.width = None + self.width = kwargs.get("width", None) """Identified width of the box.""" - self.height = None + self.height = kwargs.get("height", None) """Identified height of the box.""" def _reset(self) -> None: @@ -65,8 +65,10 @@ def __call__(self) -> dict: # 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: ")) + if self.width is None: + self.width = float(input("Enter width of box: ")) + if self.height is None: + self.height = float(input("Enter height of box: ")) self.finalized_prompt_input = True # Define a dictionary for input of the 'crop' option of CurvatureCorrection @@ -96,7 +98,10 @@ def _print_info(self) -> None: # ! ---- Automatic mode ---- ! # def from_image( - self, color: Union[list[float], np.ndarray], width: float, height: float + self, + color: Union[list[float], np.ndarray], + width: Optional[float], + height: Optional[float], ) -> dict: """Run the assistant in automatic mode. @@ -119,8 +124,12 @@ def from_image( self.pts = self._find_marks(color) # Define width and height of the box - self.width = width - self.height = height + if self.width is None: + assert width is not None, "Width not provided" + self.width = width + if self.height is None: + assert height is not None, "Height not provided" + self.height = height # Define a dictionary for input of the 'crop' option of CurvatureCorrection config = self._define_config()