pixeltable 0.2.13__py3-none-any.whl → 0.2.15__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.
Potentially problematic release.
This version of pixeltable might be problematic. Click here for more details.
- pixeltable/__init__.py +1 -1
- pixeltable/__version__.py +2 -2
- pixeltable/catalog/column.py +8 -3
- pixeltable/catalog/globals.py +8 -0
- pixeltable/catalog/table.py +25 -9
- pixeltable/catalog/table_version.py +30 -55
- pixeltable/catalog/view.py +1 -1
- pixeltable/env.py +4 -4
- pixeltable/exec/__init__.py +2 -1
- pixeltable/exec/row_update_node.py +61 -0
- pixeltable/exec/{sql_scan_node.py → sql_node.py} +120 -56
- pixeltable/exprs/__init__.py +1 -1
- pixeltable/exprs/arithmetic_expr.py +41 -16
- pixeltable/exprs/expr.py +72 -22
- pixeltable/exprs/function_call.py +64 -29
- pixeltable/exprs/globals.py +5 -1
- pixeltable/exprs/inline_array.py +18 -11
- pixeltable/exprs/method_ref.py +63 -0
- pixeltable/ext/__init__.py +9 -0
- pixeltable/ext/functions/__init__.py +8 -0
- pixeltable/ext/functions/whisperx.py +45 -5
- pixeltable/ext/functions/yolox.py +60 -14
- pixeltable/func/callable_function.py +12 -4
- pixeltable/func/expr_template_function.py +1 -1
- pixeltable/func/function.py +12 -2
- pixeltable/func/function_registry.py +24 -9
- pixeltable/func/udf.py +32 -4
- pixeltable/functions/__init__.py +1 -1
- pixeltable/functions/fireworks.py +33 -0
- pixeltable/functions/huggingface.py +96 -6
- pixeltable/functions/image.py +226 -41
- pixeltable/functions/json.py +46 -0
- pixeltable/functions/openai.py +214 -0
- pixeltable/functions/string.py +195 -218
- pixeltable/functions/timestamp.py +210 -0
- pixeltable/functions/together.py +106 -0
- pixeltable/functions/video.py +2 -2
- pixeltable/functions/{eval.py → vision.py} +170 -27
- pixeltable/functions/whisper.py +32 -0
- pixeltable/io/__init__.py +1 -1
- pixeltable/io/external_store.py +2 -2
- pixeltable/io/globals.py +133 -1
- pixeltable/io/pandas.py +82 -31
- pixeltable/iterators/video.py +55 -23
- pixeltable/metadata/__init__.py +1 -1
- pixeltable/metadata/converters/convert_18.py +39 -0
- pixeltable/metadata/notes.py +10 -0
- pixeltable/plan.py +76 -1
- pixeltable/store.py +65 -28
- pixeltable/tool/create_test_db_dump.py +8 -9
- pixeltable/tool/doc_plugins/griffe.py +4 -0
- pixeltable/type_system.py +84 -63
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/METADATA +2 -2
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/RECORD +57 -51
- pixeltable/exprs/image_member_access.py +0 -96
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/LICENSE +0 -0
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/WHEEL +0 -0
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/entry_points.txt +0 -0
pixeltable/functions/image.py
CHANGED
|
@@ -11,7 +11,7 @@ t.select(t.img_col.convert('L')).collect()
|
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
import base64
|
|
14
|
-
from typing import Optional
|
|
14
|
+
from typing import Optional
|
|
15
15
|
|
|
16
16
|
import PIL.Image
|
|
17
17
|
|
|
@@ -21,9 +21,15 @@ from pixeltable.utils.code import local_public_names
|
|
|
21
21
|
from pixeltable.exprs import Expr
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
@func.udf
|
|
24
|
+
@func.udf(is_method=True)
|
|
25
25
|
def b64_encode(img: PIL.Image.Image, image_format: str = 'png') -> str:
|
|
26
|
-
|
|
26
|
+
"""
|
|
27
|
+
Convert image to a base64-encoded string.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
img: image
|
|
31
|
+
image_format: image format [supported by PIL](https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#fully-supported-formats)
|
|
32
|
+
"""
|
|
27
33
|
import io
|
|
28
34
|
|
|
29
35
|
bytes_arr = io.BytesIO()
|
|
@@ -32,31 +38,48 @@ def b64_encode(img: PIL.Image.Image, image_format: str = 'png') -> str:
|
|
|
32
38
|
return b64_bytes.decode('utf-8')
|
|
33
39
|
|
|
34
40
|
|
|
35
|
-
@func.udf(substitute_fn=PIL.Image.alpha_composite)
|
|
41
|
+
@func.udf(substitute_fn=PIL.Image.alpha_composite, is_method=True)
|
|
36
42
|
def alpha_composite(im1: PIL.Image.Image, im2: PIL.Image.Image) -> PIL.Image.Image:
|
|
43
|
+
"""
|
|
44
|
+
Alpha composite `im2` over `im1`.
|
|
45
|
+
|
|
46
|
+
Equivalent to [`PIL.Image.alpha_composite()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.alpha_composite)
|
|
47
|
+
"""
|
|
37
48
|
pass
|
|
38
49
|
|
|
39
50
|
|
|
40
|
-
@func.udf(substitute_fn=PIL.Image.blend)
|
|
51
|
+
@func.udf(substitute_fn=PIL.Image.blend, is_method=True)
|
|
41
52
|
def blend(im1: PIL.Image.Image, im2: PIL.Image.Image, alpha: float) -> PIL.Image.Image:
|
|
42
|
-
|
|
53
|
+
"""
|
|
54
|
+
Return a new image by interpolating between two input images, using a constant alpha.
|
|
43
55
|
|
|
56
|
+
Equivalent to [`PIL.Image.blend()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.blend)
|
|
57
|
+
"""
|
|
58
|
+
pass
|
|
44
59
|
|
|
45
|
-
@func.udf(substitute_fn=PIL.Image.composite)
|
|
60
|
+
@func.udf(substitute_fn=PIL.Image.composite, is_method=True)
|
|
46
61
|
def composite(image1: PIL.Image.Image, image2: PIL.Image.Image, mask: PIL.Image.Image) -> PIL.Image.Image:
|
|
62
|
+
"""
|
|
63
|
+
Return a composite image by blending two images using a mask.
|
|
64
|
+
|
|
65
|
+
Equivalent to [`PIL.Image.composite()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.composite)
|
|
66
|
+
"""
|
|
47
67
|
pass
|
|
48
68
|
|
|
49
69
|
|
|
50
70
|
# PIL.Image.Image methods
|
|
51
71
|
|
|
52
|
-
|
|
53
72
|
# Image.convert()
|
|
54
|
-
@func.udf
|
|
73
|
+
@func.udf(is_method=True)
|
|
55
74
|
def convert(self: PIL.Image.Image, mode: str) -> PIL.Image.Image:
|
|
56
75
|
"""
|
|
57
76
|
Convert the image to a different mode.
|
|
58
77
|
|
|
59
|
-
Equivalent to
|
|
78
|
+
Equivalent to
|
|
79
|
+
[`PIL.Image.Image.convert()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.convert).
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
mode: The mode to convert to. See the [Pillow documentation](https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes) for a list of supported modes.
|
|
60
83
|
"""
|
|
61
84
|
return self.convert(mode)
|
|
62
85
|
|
|
@@ -69,23 +92,39 @@ def _(self: Expr, mode: str) -> ts.ColumnType:
|
|
|
69
92
|
|
|
70
93
|
|
|
71
94
|
# Image.crop()
|
|
72
|
-
@func.udf(substitute_fn=PIL.Image.Image.crop, param_types=[ts.ImageType(), ts.ArrayType((4,), dtype=ts.IntType())])
|
|
73
|
-
def crop(self: PIL.Image.Image, box:
|
|
95
|
+
@func.udf(substitute_fn=PIL.Image.Image.crop, param_types=[ts.ImageType(), ts.ArrayType((4,), dtype=ts.IntType())], is_method=True)
|
|
96
|
+
def crop(self: PIL.Image.Image, box: tuple[int, int, int, int]) -> PIL.Image.Image:
|
|
97
|
+
"""
|
|
98
|
+
Return a rectangular region from the image. The box is a 4-tuple defining the left, upper, right, and lower pixel
|
|
99
|
+
coordinates.
|
|
100
|
+
|
|
101
|
+
Equivalent to
|
|
102
|
+
[`PIL.Image.Image.crop()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.crop)
|
|
103
|
+
"""
|
|
74
104
|
pass
|
|
75
105
|
|
|
76
106
|
|
|
77
107
|
@crop.conditional_return_type
|
|
78
|
-
def _(self: Expr, box:
|
|
108
|
+
def _(self: Expr, box: tuple[int, int, int, int]) -> ts.ColumnType:
|
|
79
109
|
input_type = self.col_type
|
|
80
110
|
assert isinstance(input_type, ts.ImageType)
|
|
81
|
-
if isinstance(box, list) and all(isinstance(x, int) for x in box):
|
|
111
|
+
if (isinstance(box, list) or isinstance(box, tuple)) and len(box) == 4 and all(isinstance(x, int) for x in box):
|
|
82
112
|
return ts.ImageType(size=(box[2] - box[0], box[3] - box[1]), mode=input_type.mode, nullable=input_type.nullable)
|
|
83
113
|
return ts.ImageType(mode=input_type.mode, nullable=input_type.nullable) # we can't compute the size statically
|
|
84
114
|
|
|
85
115
|
|
|
86
116
|
# Image.getchannel()
|
|
87
|
-
@func.udf(substitute_fn=PIL.Image.Image.getchannel)
|
|
117
|
+
@func.udf(substitute_fn=PIL.Image.Image.getchannel, is_method=True)
|
|
88
118
|
def getchannel(self: PIL.Image.Image, channel: int) -> PIL.Image.Image:
|
|
119
|
+
"""
|
|
120
|
+
Return an L-mode image containing a single channel of the original image.
|
|
121
|
+
|
|
122
|
+
Equivalent to
|
|
123
|
+
[`PIL.Image.Image.getchannel()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getchannel)
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
channel: The channel to extract. This is a 0-based index.
|
|
127
|
+
"""
|
|
89
128
|
pass
|
|
90
129
|
|
|
91
130
|
|
|
@@ -97,31 +136,64 @@ def _(self: Expr) -> ts.ColumnType:
|
|
|
97
136
|
|
|
98
137
|
|
|
99
138
|
# Image.resize()
|
|
100
|
-
@func.udf(param_types=[ts.ImageType(), ts.ArrayType((2,), dtype=ts.IntType())])
|
|
101
|
-
def resize(self: PIL.Image.Image, size:
|
|
139
|
+
@func.udf(param_types=[ts.ImageType(), ts.ArrayType((2,), dtype=ts.IntType())], is_method=True)
|
|
140
|
+
def resize(self: PIL.Image.Image, size: tuple[int, int]) -> PIL.Image.Image:
|
|
141
|
+
"""
|
|
142
|
+
Return a resized copy of the image. The size parameter is a tuple containing the width and height of the new image.
|
|
143
|
+
|
|
144
|
+
Equivalent to
|
|
145
|
+
[`PIL.Image.Image.resize()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize)
|
|
146
|
+
"""
|
|
102
147
|
return self.resize(size)
|
|
103
148
|
|
|
104
149
|
|
|
105
150
|
@resize.conditional_return_type
|
|
106
|
-
def _(self: Expr, size:
|
|
151
|
+
def _(self: Expr, size: tuple[int, int]) -> ts.ColumnType:
|
|
107
152
|
input_type = self.col_type
|
|
108
153
|
assert isinstance(input_type, ts.ImageType)
|
|
109
154
|
return ts.ImageType(size=size, mode=input_type.mode, nullable=input_type.nullable)
|
|
110
155
|
|
|
111
156
|
|
|
112
157
|
# Image.rotate()
|
|
113
|
-
@func.udf
|
|
158
|
+
@func.udf(is_method=True)
|
|
114
159
|
def rotate(self: PIL.Image.Image, angle: int) -> PIL.Image.Image:
|
|
160
|
+
"""
|
|
161
|
+
Return a copy of the image rotated by the given angle.
|
|
162
|
+
|
|
163
|
+
Equivalent to
|
|
164
|
+
[`PIL.Image.Image.rotate()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.rotate)
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
angle: The angle to rotate the image, in degrees. Positive angles are counter-clockwise.
|
|
168
|
+
"""
|
|
115
169
|
return self.rotate(angle)
|
|
116
170
|
|
|
117
171
|
|
|
118
|
-
@func.udf(substitute_fn=PIL.Image.Image.effect_spread)
|
|
172
|
+
@func.udf(substitute_fn=PIL.Image.Image.effect_spread, is_method=True)
|
|
119
173
|
def effect_spread(self: PIL.Image.Image, distance: int) -> PIL.Image.Image:
|
|
174
|
+
"""
|
|
175
|
+
Randomly spread pixels in an image.
|
|
176
|
+
|
|
177
|
+
Equivalent to
|
|
178
|
+
[`PIL.Image.Image.effect_spread()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.effect_spread)
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
distance: The distance to spread pixels.
|
|
182
|
+
"""
|
|
120
183
|
pass
|
|
121
184
|
|
|
122
185
|
|
|
123
|
-
@func.udf(substitute_fn=PIL.Image.Image.transpose)
|
|
186
|
+
@func.udf(substitute_fn=PIL.Image.Image.transpose, is_method=True)
|
|
124
187
|
def transpose(self: PIL.Image.Image, method: int) -> PIL.Image.Image:
|
|
188
|
+
"""
|
|
189
|
+
Transpose the image.
|
|
190
|
+
|
|
191
|
+
Equivalent to
|
|
192
|
+
[`PIL.Image.Image.transpose()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transpose)
|
|
193
|
+
|
|
194
|
+
Args:
|
|
195
|
+
method: The transpose method. See the [Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transpose) for a list of supported methods.
|
|
196
|
+
"""
|
|
125
197
|
pass
|
|
126
198
|
|
|
127
199
|
|
|
@@ -132,53 +204,128 @@ def _(self: Expr) -> ts.ColumnType:
|
|
|
132
204
|
return self.col_type
|
|
133
205
|
|
|
134
206
|
|
|
135
|
-
@func.udf(substitute_fn=PIL.Image.Image.entropy)
|
|
207
|
+
@func.udf(substitute_fn=PIL.Image.Image.entropy, is_method=True)
|
|
136
208
|
def entropy(self: PIL.Image.Image, mask: Optional[PIL.Image.Image] = None, extrema: Optional[list] = None) -> float:
|
|
209
|
+
"""
|
|
210
|
+
Returns the entropy of the image, optionally using a mask and extrema.
|
|
211
|
+
|
|
212
|
+
Equivalent to
|
|
213
|
+
[`PIL.Image.Image.entropy()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.entropy)
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
mask: An optional mask image.
|
|
217
|
+
extrema: An optional list of extrema.
|
|
218
|
+
"""
|
|
137
219
|
pass
|
|
138
220
|
|
|
139
221
|
|
|
140
|
-
@func.udf(substitute_fn=PIL.Image.Image.getbands)
|
|
141
|
-
def getbands(self: PIL.Image.Image) ->
|
|
222
|
+
@func.udf(substitute_fn=PIL.Image.Image.getbands, is_method=True)
|
|
223
|
+
def getbands(self: PIL.Image.Image) -> tuple[str]:
|
|
224
|
+
"""
|
|
225
|
+
Return a tuple containing the names of the image bands.
|
|
226
|
+
|
|
227
|
+
Equivalent to
|
|
228
|
+
[`PIL.Image.Image.getbands()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getbands)
|
|
229
|
+
"""
|
|
142
230
|
pass
|
|
143
231
|
|
|
144
232
|
|
|
145
|
-
@func.udf(substitute_fn=PIL.Image.Image.getbbox)
|
|
146
|
-
def getbbox(self: PIL.Image.Image) ->
|
|
233
|
+
@func.udf(substitute_fn=PIL.Image.Image.getbbox, is_method=True)
|
|
234
|
+
def getbbox(self: PIL.Image.Image, *, alpha_only: bool = True) -> tuple[int, int, int, int]:
|
|
235
|
+
"""
|
|
236
|
+
Return a bounding box for the non-zero regions of the image.
|
|
237
|
+
|
|
238
|
+
Equivalent to [`PIL.Image.Image.getbbox()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getbbox)
|
|
239
|
+
|
|
240
|
+
Args:
|
|
241
|
+
alpha_only: If `True`, and the image has an alpha channel, trim transparent pixels. Otherwise, trim pixels when all channels are zero.
|
|
242
|
+
"""
|
|
147
243
|
pass
|
|
148
244
|
|
|
149
245
|
|
|
150
|
-
@func.udf(substitute_fn=PIL.Image.Image.getcolors)
|
|
151
|
-
def getcolors(self: PIL.Image.Image, maxcolors: int) ->
|
|
246
|
+
@func.udf(substitute_fn=PIL.Image.Image.getcolors, is_method=True)
|
|
247
|
+
def getcolors(self: PIL.Image.Image, maxcolors: int = 256) -> tuple[tuple[int, int, int], int]:
|
|
248
|
+
"""
|
|
249
|
+
Return a list of colors used in the image, up to a maximum of `maxcolors`.
|
|
250
|
+
|
|
251
|
+
Equivalent to
|
|
252
|
+
[`PIL.Image.Image.getcolors()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getcolors)
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
maxcolors: The maximum number of colors to return.
|
|
256
|
+
"""
|
|
152
257
|
pass
|
|
153
258
|
|
|
154
259
|
|
|
155
|
-
@func.udf(substitute_fn=PIL.Image.Image.getextrema)
|
|
156
|
-
def getextrema(self: PIL.Image.Image) ->
|
|
260
|
+
@func.udf(substitute_fn=PIL.Image.Image.getextrema, is_method=True)
|
|
261
|
+
def getextrema(self: PIL.Image.Image) -> tuple[int, int]:
|
|
262
|
+
"""
|
|
263
|
+
Return a 2-tuple containing the minimum and maximum pixel values of the image.
|
|
264
|
+
|
|
265
|
+
Equivalent to
|
|
266
|
+
[`PIL.Image.Image.getextrema()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getextrema)
|
|
267
|
+
"""
|
|
157
268
|
pass
|
|
158
269
|
|
|
159
270
|
|
|
160
|
-
@func.udf(substitute_fn=PIL.Image.Image.getpalette)
|
|
161
|
-
def getpalette(self: PIL.Image.Image, mode: Optional[str] = None) ->
|
|
271
|
+
@func.udf(substitute_fn=PIL.Image.Image.getpalette, is_method=True)
|
|
272
|
+
def getpalette(self: PIL.Image.Image, mode: Optional[str] = None) -> tuple[int]:
|
|
273
|
+
"""
|
|
274
|
+
Return the palette of the image, optionally converting it to a different mode.
|
|
275
|
+
|
|
276
|
+
Equivalent to
|
|
277
|
+
[`PIL.Image.Image.getpalette()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getpalette)
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
mode: The mode to convert the palette to.
|
|
281
|
+
"""
|
|
162
282
|
pass
|
|
163
283
|
|
|
164
284
|
|
|
165
|
-
@func.udf(param_types=[ts.ImageType(), ts.ArrayType((2,), dtype=ts.IntType())])
|
|
166
|
-
def getpixel(self: PIL.Image.Image, xy: tuple[int, int]) ->
|
|
285
|
+
@func.udf(param_types=[ts.ImageType(), ts.ArrayType((2,), dtype=ts.IntType())], is_method=True)
|
|
286
|
+
def getpixel(self: PIL.Image.Image, xy: tuple[int, int]) -> tuple[int]:
|
|
287
|
+
"""
|
|
288
|
+
Return the pixel value at the given position. The position `xy` is a tuple containing the x and y coordinates.
|
|
289
|
+
|
|
290
|
+
Equivalent to
|
|
291
|
+
[`PIL.Image.Image.getpixel()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getpixel)
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
xy: The coordinates, given as (x, y).
|
|
295
|
+
"""
|
|
167
296
|
# `xy` will be a list; `tuple(xy)` is necessary for pillow 9 compatibility
|
|
168
297
|
return self.getpixel(tuple(xy))
|
|
169
298
|
|
|
170
299
|
|
|
171
|
-
@func.udf(substitute_fn=PIL.Image.Image.getprojection)
|
|
172
|
-
def getprojection(self: PIL.Image.Image) ->
|
|
300
|
+
@func.udf(substitute_fn=PIL.Image.Image.getprojection, is_method=True)
|
|
301
|
+
def getprojection(self: PIL.Image.Image) -> tuple[int]:
|
|
302
|
+
"""
|
|
303
|
+
Return two sequences representing the horizontal and vertical projection of the image.
|
|
304
|
+
|
|
305
|
+
Equivalent to
|
|
306
|
+
[`PIL.Image.Image.getprojection()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getprojection)
|
|
307
|
+
"""
|
|
173
308
|
pass
|
|
174
309
|
|
|
175
310
|
|
|
176
|
-
@func.udf(substitute_fn=PIL.Image.Image.histogram)
|
|
177
|
-
def histogram(
|
|
311
|
+
@func.udf(substitute_fn=PIL.Image.Image.histogram, is_method=True)
|
|
312
|
+
def histogram(
|
|
313
|
+
self: PIL.Image.Image, mask: Optional[PIL.Image.Image] = None, extrema: Optional[list] = None
|
|
314
|
+
) -> list[int]:
|
|
315
|
+
"""
|
|
316
|
+
Return a histogram for the image.
|
|
317
|
+
|
|
318
|
+
Equivalent to
|
|
319
|
+
[`PIL.Image.Image.histogram()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.histogram)
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
mask: An optional mask image.
|
|
323
|
+
extrema: An optional list of extrema.
|
|
324
|
+
"""
|
|
178
325
|
pass
|
|
179
326
|
|
|
180
327
|
|
|
181
|
-
@func.udf(substitute_fn=PIL.Image.Image.quantize)
|
|
328
|
+
@func.udf(substitute_fn=PIL.Image.Image.quantize, is_method=True)
|
|
182
329
|
def quantize(
|
|
183
330
|
self: PIL.Image.Image,
|
|
184
331
|
colors: int = 256,
|
|
@@ -187,14 +334,52 @@ def quantize(
|
|
|
187
334
|
palette: Optional[int] = None,
|
|
188
335
|
dither: int = PIL.Image.Dither.FLOYDSTEINBERG,
|
|
189
336
|
) -> PIL.Image.Image:
|
|
337
|
+
"""
|
|
338
|
+
Convert the image to 'P' mode with the specified number of colors.
|
|
339
|
+
|
|
340
|
+
Equivalent to
|
|
341
|
+
[`PIL.Image.Image.quantize()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize)
|
|
342
|
+
|
|
343
|
+
Args:
|
|
344
|
+
colors: The number of colors to quantize to.
|
|
345
|
+
method: The quantization method. See the [Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize) for a list of supported methods.
|
|
346
|
+
kmeans: The number of k-means clusters to use.
|
|
347
|
+
palette: The palette to use.
|
|
348
|
+
dither: The dithering method. See the [Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize) for a list of supported methods.
|
|
349
|
+
"""
|
|
190
350
|
pass
|
|
191
351
|
|
|
192
352
|
|
|
193
|
-
@func.udf(substitute_fn=PIL.Image.Image.reduce)
|
|
194
|
-
def reduce(self: PIL.Image.Image, factor: int, box: Optional[
|
|
353
|
+
@func.udf(substitute_fn=PIL.Image.Image.reduce, is_method=True)
|
|
354
|
+
def reduce(self: PIL.Image.Image, factor: int, box: Optional[tuple[int]] = None) -> PIL.Image.Image:
|
|
355
|
+
"""
|
|
356
|
+
Reduce the image by the given factor.
|
|
357
|
+
|
|
358
|
+
Equivalent to
|
|
359
|
+
[`PIL.Image.Image.reduce()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.reduce)
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
factor: The reduction factor.
|
|
363
|
+
box: An optional 4-tuple of ints providing the source image region to be reduced. The values must be within (0, 0, width, height) rectangle. If omitted or None, the entire source is used.
|
|
364
|
+
"""
|
|
195
365
|
pass
|
|
196
366
|
|
|
197
367
|
|
|
368
|
+
@func.udf(is_property=True)
|
|
369
|
+
def width(self: PIL.Image.Image) -> int:
|
|
370
|
+
return self.width
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
@func.udf(is_property=True)
|
|
374
|
+
def height(self: PIL.Image.Image) -> int:
|
|
375
|
+
return self.height
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
@func.udf(is_property=True)
|
|
379
|
+
def mode(self: PIL.Image.Image) -> str:
|
|
380
|
+
return self.mode
|
|
381
|
+
|
|
382
|
+
|
|
198
383
|
__all__ = local_public_names(__name__)
|
|
199
384
|
|
|
200
385
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pixeltable [UDFs](https://pixeltable.readme.io/docs/user-defined-functions-udfs) for `JsonType`.
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
```python
|
|
6
|
+
import pixeltable as pxt
|
|
7
|
+
|
|
8
|
+
t = pxt.get_table(...)
|
|
9
|
+
t.select(pxt.functions.json.make_list()).collect()
|
|
10
|
+
```
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
import pixeltable.func as func
|
|
16
|
+
import pixeltable.type_system as ts
|
|
17
|
+
from pixeltable.utils.code import local_public_names
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@func.uda(
|
|
21
|
+
update_types=[ts.JsonType(nullable=True)],
|
|
22
|
+
value_type=ts.JsonType(),
|
|
23
|
+
requires_order_by=False,
|
|
24
|
+
allows_window=False,
|
|
25
|
+
)
|
|
26
|
+
class make_list(func.Aggregator):
|
|
27
|
+
"""
|
|
28
|
+
Collects arguments into a list.
|
|
29
|
+
"""
|
|
30
|
+
def __init__(self):
|
|
31
|
+
self.output: list[Any] = []
|
|
32
|
+
|
|
33
|
+
def update(self, obj: Any) -> None:
|
|
34
|
+
if obj is None:
|
|
35
|
+
return
|
|
36
|
+
self.output.append(obj)
|
|
37
|
+
|
|
38
|
+
def value(self) -> list[Any]:
|
|
39
|
+
return self.output
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__all__ = local_public_names(__name__)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def __dir__():
|
|
46
|
+
return __all__
|