opsci-toolbox 0.0.6__py3-none-any.whl → 0.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,11 +8,11 @@ def open_image(image_path: str) -> Image:
8
8
  """
9
9
  Open and return an image.
10
10
 
11
- Parameters:
12
- - image_path (str): The path to the image file.
11
+ Args:
12
+ image_path (str): The path to the image file.
13
13
 
14
14
  Returns:
15
- - Image object: The opened image.
15
+ Image object: The opened image.
16
16
  """
17
17
  try:
18
18
  # Open the image file
@@ -26,13 +26,13 @@ def save_image(image: Image, output_path: str, name: str) -> str:
26
26
  """
27
27
  Save an image to the local disk.
28
28
 
29
- Parameters:
30
- - image (Image object): The image to be saved.
31
- - output_path (str): The path to save the image.
32
- - name (str): The name of the saved image file.
29
+ Args:
30
+ image (Image object): The image to be saved.
31
+ output_path (str): The path to save the image.
32
+ name (str): The name of the saved image file.
33
33
 
34
34
  Returns:
35
- - str: The file path where the image is saved, or an error message if saving fails.
35
+ str: The file path where the image is saved, or an error message if saving fails.
36
36
  """
37
37
  try:
38
38
  # Save the image to the specified path
@@ -47,14 +47,14 @@ def convert_image_format(input_path: str, output_path: str, output_filename: str
47
47
  """
48
48
  Convert an image to another image format (e.g., from PNG to JPEG).
49
49
 
50
- Parameters:
51
- - input_path (str): The path to the input image file.
52
- - output_path (str): The path to save the converted image.
53
- - output_filename (str): The name of the converted image file.
54
- - output_format (str): The format to which the image should be converted. Default is "JPEG".
50
+ Args:
51
+ input_path (str): The path to the input image file.
52
+ output_path (str): The path to save the converted image.
53
+ output_filename (str): The name of the converted image file.
54
+ output_format (str): The format to which the image should be converted. Default is "JPEG".
55
55
 
56
56
  Returns:
57
- - str: The file path where the converted image is saved, or an error message if conversion fails.
57
+ str: The file path where the converted image is saved, or an error message if conversion fails.
58
58
  """
59
59
  try:
60
60
  file_path = os.path.join(output_path, output_filename + "." + output_format)
@@ -73,13 +73,13 @@ def resize_image(image: Image, new_width: int, new_height: int) -> Image:
73
73
  """
74
74
  Resize an image to the specified width and height.
75
75
 
76
- Parameters:
77
- - image (PIL.Image.Image): The PIL image object to be resized.
78
- - new_width (int): The desired width of the resized image.
79
- - new_height (int): The desired height of the resized image.
76
+ Args:
77
+ image (PIL.Image.Image): The PIL image object to be resized.
78
+ new_width (int): The desired width of the resized image.
79
+ new_height (int): The desired height of the resized image.
80
80
 
81
81
  Returns:
82
- - PIL.Image.Image: The resized image.
82
+ PIL.Image.Image: The resized image.
83
83
  """
84
84
  try:
85
85
  # Resize the image
@@ -93,15 +93,15 @@ def crop_image(image: Image, x: int, y: int, width: int, height: int) -> Image:
93
93
  """
94
94
  Crop an image based on the specified coordinates and dimensions.
95
95
 
96
- Parameters:
97
- - image (PIL.Image.Image): The PIL image object to be cropped.
98
- - x (int): The x-coordinate of the top-left corner of the cropping region.
99
- - y (int): The y-coordinate of the top-left corner of the cropping region.
100
- - width (int): The width of the cropping region.
101
- - height (int): The height of the cropping region.
96
+ Args:
97
+ image (PIL.Image.Image): The PIL image object to be cropped.
98
+ x (int): The x-coordinate of the top-left corner of the cropping region.
99
+ y (int): The y-coordinate of the top-left corner of the cropping region.
100
+ width (int): The width of the cropping region.
101
+ height (int): The height of the cropping region.
102
102
 
103
103
  Returns:
104
- - PIL.Image.Image: The cropped image.
104
+ PIL.Image.Image: The cropped image.
105
105
  """
106
106
  try:
107
107
  # Crop the image
@@ -115,12 +115,12 @@ def flip_image(image: Image, direction: str = 'horizontal') -> Image:
115
115
  """
116
116
  Flip an image horizontally or vertically.
117
117
 
118
- Parameters:
119
- - image (PIL.Image.Image): The PIL image object to be flipped.
120
- - direction (str): The direction of the flip ('horizontal' or 'vertical'). Default is 'horizontal'.
118
+ Args:
119
+ image (PIL.Image.Image): The PIL image object to be flipped.
120
+ direction (str): The direction of the flip ('horizontal' or 'vertical'). Default is 'horizontal'.
121
121
 
122
122
  Returns:
123
- - PIL.Image.Image: The flipped image.
123
+ PIL.Image.Image: The flipped image.
124
124
  """
125
125
  try:
126
126
  # Flip the image
@@ -141,12 +141,12 @@ def rotate_image(image: Image, angle: float) -> Image:
141
141
  """
142
142
  Rotate an image by the given angle (in degrees).
143
143
 
144
- Parameters:
145
- - image (PIL.Image.Image): The PIL image object to be rotated.
146
- - angle (float): The angle by which to rotate the image (in degrees).
144
+ Args:
145
+ image (PIL.Image.Image): The PIL image object to be rotated.
146
+ angle (float): The angle by which to rotate the image (in degrees).
147
147
 
148
148
  Returns:
149
- - PIL.Image.Image: The rotated image.
149
+ PIL.Image.Image: The rotated image.
150
150
  """
151
151
  try:
152
152
  # Rotate the image
@@ -160,11 +160,11 @@ def convert_to_grayscale(image: Image) -> Image:
160
160
  """
161
161
  Convert a color image to grayscale.
162
162
 
163
- Parameters:
164
- - image (PIL.Image.Image): The PIL image object to be converted.
163
+ Args:
164
+ image (PIL.Image.Image): The PIL image object to be converted.
165
165
 
166
166
  Returns:
167
- - PIL.Image.Image: The grayscale image.
167
+ PIL.Image.Image: The grayscale image.
168
168
  """
169
169
  try:
170
170
  # Convert the image to grayscale
@@ -178,11 +178,11 @@ def PIL_get_image_size(image: Image) -> tuple:
178
178
  """
179
179
  Get PILLOW image size.
180
180
 
181
- Parameters:
182
- - image (PIL.Image.Image): The PIL image object.
181
+ Args:
182
+ image (PIL.Image.Image): The PIL image object.
183
183
 
184
184
  Returns:
185
- - tuple: A tuple containing the width and height of the image.
185
+ tuple: A tuple containing the width and height of the image.
186
186
  """
187
187
  width, height = image.size
188
188
  return width, height
@@ -191,11 +191,11 @@ def cv_get_image_size(image) -> tuple:
191
191
  """
192
192
  Get cv2 image size.
193
193
 
194
- Parameters:
195
- - image: The cv2 image array.
194
+ Args:
195
+ image: The cv2 image array.
196
196
 
197
197
  Returns:
198
- - tuple: A tuple containing the width and height of the image.
198
+ tuple: A tuple containing the width and height of the image.
199
199
  """
200
200
  height, width, _ = image.shape
201
201
  return width, height
@@ -204,11 +204,11 @@ def convert_PIL_to_cv(image: Image) -> np.ndarray:
204
204
  """
205
205
  Convert an image from Pillow to CV2.
206
206
 
207
- Parameters:
208
- - image (PIL.Image.Image): The PIL image object.
207
+ Args:
208
+ image (PIL.Image.Image): The PIL image object.
209
209
 
210
210
  Returns:
211
- - numpy.ndarray: The converted cv2 image array.
211
+ numpy.ndarray: The converted cv2 image array.
212
212
  """
213
213
  numpy_array = np.array(image)
214
214
  cv2_image = cv2.cvtColor(numpy_array, cv2.COLOR_RGB2BGR)
@@ -399,14 +399,14 @@ def apply_mask(image: np.ndarray, mask: np.ndarray, color_mask: list = [255, 255
399
399
  Apply a transparent color mask on an image.
400
400
 
401
401
  Args:
402
- image (np.ndarray): The input image to which the mask will be applied.
403
- mask (np.ndarray): The binary mask indicating where to apply the color mask.
402
+ image (numpy.ndarray): The input image to which the mask will be applied.
403
+ mask (numpy.ndarray): The binary mask indicating where to apply the color mask.
404
404
  color_mask (list, optional): The RGB color to use for the mask. Default is white [255, 255, 255].
405
405
  reverse (bool, optional): If True, apply the color mask where the mask is False; otherwise, apply where True. Default is True.
406
406
  transparency (float, optional): The transparency level of the color mask (0.0 to 1.0). Default is 1.0 (opaque).
407
407
 
408
408
  Returns:
409
- np.ndarray: The image with the color mask applied.
409
+ numpy.ndarray: The image with the color mask applied.
410
410
  """
411
411
  # Validate transparency value
412
412
  transparency = max(0.0, min(1.0, transparency))
@@ -606,14 +606,4 @@ def sv_annotate_image_label(
606
606
  # Annotate the image with the labels
607
607
  annotated_image = label_annotator.annotate(scene=image, detections=detections, labels=labels)
608
608
 
609
- return annotated_image
610
-
611
-
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
609
+ return annotated_image