@@ -29,20 +29,18 @@ class SobelOperator(Operator):
29
29
30
30
DEFAULT_INPUT_FOLDER = Path .cwd () / "input"
31
31
32
- def __init__ (self , fragment : Fragment , * args , input_folder : Path , ** kwargs ):
32
+ def __init__ (self , fragment : Fragment , * args , input_path : Path , ** kwargs ):
33
33
"""Create an instance to be part of the given application (fragment).
34
34
35
35
Args:
36
36
fragment (Fragment): An instance of the Application class which is derived from Fragment
37
- input_folder (Path): The folder to read the image file from
37
+ input_path (Path): The path of the input image file or folder containing the image file
38
38
"""
39
39
self .index = 0
40
40
41
41
# May want to validate the path, but it should really be validated when the compute function is called, also,
42
42
# when file path as input is supported in the operator or execution context, input_folder needs not an attribute.
43
- self .input_folder = (
44
- input_folder if (input_folder and input_folder .is_dir ()) else SobelOperator .DEFAULT_INPUT_FOLDER
45
- )
43
+ self .input_path = input_path if input_path else SobelOperator .DEFAULT_INPUT_FOLDER
46
44
47
45
# Need to call the base class constructor last
48
46
super ().__init__ (fragment , * args , ** kwargs )
@@ -59,12 +57,12 @@ def compute(self, op_input, op_output, context):
59
57
# Ideally the op_input or execution context should provide the file path
60
58
# to read data from, for operators that are file input based.
61
59
# For now, use a temporary way to get input path. e.g. value set on init
62
- input_folder = self .input_folder
63
- print (f"Input from: { input_folder } , whose absolute path: { input_folder .absolute ()} " )
64
- if input_folder .is_dir ():
65
- input_file = next (input_folder .glob ("*.*" )) # take the first file
60
+ input_path = self .input_path
61
+ print (f"Input from: { input_path } , whose absolute path: { input_path .absolute ()} " )
62
+ if input_path .is_dir ():
63
+ input_path = next (input_path .glob ("*.*" )) # take the first file
66
64
67
- data_in = io .imread (input_file )[:, :, :3 ] # discard alpha channel if exists
65
+ data_in = io .imread (input_path )[:, :, :3 ] # discard alpha channel if exists
68
66
data_out = filters .sobel (data_in )
69
67
70
68
op_output .emit (data_out , "out1" )
0 commit comments