machinevision-toolbox-python 2.0.1__py3-none-any.whl → 2.2.0__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.
- {machinevision_toolbox_python-2.0.1.dist-info → machinevision_toolbox_python-2.2.0.dist-info}/METADATA +13 -5
- {machinevision_toolbox_python-2.0.1.dist-info → machinevision_toolbox_python-2.2.0.dist-info}/RECORD +23 -33
- {machinevision_toolbox_python-2.0.1.dist-info → machinevision_toolbox_python-2.2.0.dist-info}/WHEEL +1 -1
- machinevisiontoolbox/BundleAdjust.py +1 -1
- machinevisiontoolbox/Camera.py +95 -80
- machinevisiontoolbox/ImageBlobs.py +10 -4
- machinevisiontoolbox/ImageCore.py +105 -97
- machinevisiontoolbox/ImageFiducials.py +62 -10
- machinevisiontoolbox/ImageIO.py +5 -1
- machinevisiontoolbox/ImageLineFeatures.py +9 -1
- machinevisiontoolbox/ImagePointFeatures.py +29 -8
- machinevisiontoolbox/ImageProcessing.py +1 -1
- machinevisiontoolbox/ImageRegionFeatures.py +25 -6
- machinevisiontoolbox/ImageWholeFeatures.py +113 -72
- machinevisiontoolbox/Sources.py +1 -1
- machinevisiontoolbox/__init__.py +1 -1
- machinevisiontoolbox/base/imageio.py +68 -33
- machinevisiontoolbox/bin/_iminteractive.py +461 -0
- machinevisiontoolbox/bin/bagtool.py +120 -6
- machinevisiontoolbox/bin/imtool.py +34 -5
- machinevisiontoolbox/bin/mvtbtool.py +93 -18
- machinevisiontoolbox/ImageCore.docstring +0 -2877
- machinevisiontoolbox/aruco0.pdf +0 -0
- machinevisiontoolbox/aruco50.pdf +0 -0
- machinevisiontoolbox/bin/labeltool.py +0 -147
- machinevisiontoolbox/blocks/Icons/icons.sh +0 -4
- machinevisiontoolbox/cvfuncs.py +0 -40
- machinevisiontoolbox/docbugs.py +0 -47
- machinevisiontoolbox/newcameras.py +0 -55
- machinevisiontoolbox/test_skimage.py +0 -12
- machinevisiontoolbox/testblobplots.py +0 -17
- machinevisiontoolbox/x.json +0 -296
- {machinevision_toolbox_python-2.0.1.dist-info → machinevision_toolbox_python-2.2.0.dist-info}/entry_points.txt +0 -0
- {machinevision_toolbox_python-2.0.1.dist-info → machinevision_toolbox_python-2.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,2877 +0,0 @@
|
|
|
1
|
-
#################### ImageCore.py/Image.__init__
|
|
2
|
-
"""
|
|
3
|
-
Create an Image instance
|
|
4
|
-
|
|
5
|
-
:param image: image data
|
|
6
|
-
:type image: array_like(H,W), :class:`Image`
|
|
7
|
-
:param colororder: order of color channels
|
|
8
|
-
:type colororder: str, dict
|
|
9
|
-
:param copy: copy the image data, defaults to False
|
|
10
|
-
:type copy: bool, optional
|
|
11
|
-
:param size: new size for the image, defaults to None
|
|
12
|
-
:type size: tuple, optional
|
|
13
|
-
:param dtype: data type for image, defaults to same type as ``image``
|
|
14
|
-
:type dtype: str or NumPy dtype, optional
|
|
15
|
-
:param name: name of image, defaults to None
|
|
16
|
-
:type name: str, optional
|
|
17
|
-
:param id: numeric id of image, typically a sequence number, defaults to None
|
|
18
|
-
:type id: int, optional
|
|
19
|
-
:param domain: domain of image, defaults to None
|
|
20
|
-
:type domain: array_like(W), array_like(H), optional
|
|
21
|
-
:param binary: create binary image, non-zero values are set to True, defaults to False
|
|
22
|
-
:type binary: bool, optional
|
|
23
|
-
:raises TypeError: unknown type passed to constructor
|
|
24
|
-
|
|
25
|
-
Create a new :class:`Image` instance which contains pixel values as well as
|
|
26
|
-
information about image size, datatype, color planes and domain. The pixel
|
|
27
|
-
data is stored in a NumPy array, encapsulated by the object.
|
|
28
|
-
|
|
29
|
-
An image is considered to be a two-dimensional (width x height) grid of pixel
|
|
30
|
-
values, that lie within one or more "color" planes.
|
|
31
|
-
|
|
32
|
-
The image data can be specified by:
|
|
33
|
-
|
|
34
|
-
- a NumPy 2D or 3D array for a greyscale or color image respectively. For
|
|
35
|
-
the latter case, the last index represents the color plane::
|
|
36
|
-
|
|
37
|
-
Image(nd.zeros((100, 200)))
|
|
38
|
-
Image(nd.zeros((100, 200, 4)), colororder="WXYZ")
|
|
39
|
-
|
|
40
|
-
- a lists of lists of pixel values, each inner list must have the same
|
|
41
|
-
number of elements (columns)::
|
|
42
|
-
|
|
43
|
-
Image([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
|
|
44
|
-
|
|
45
|
-
- a range of class methods that serve as constructors for common image types such as
|
|
46
|
-
:meth:`Zeros`, :meth:`Constant`, :meth:`Random` and :meth:`String`, or
|
|
47
|
-
read an image from a file :meth:`Read`.
|
|
48
|
-
|
|
49
|
-
- an existing :class:`Image` instance.
|
|
50
|
-
|
|
51
|
-
**Pixel datatype**
|
|
52
|
-
|
|
53
|
-
If ``dtype`` is a string or a NumPy dtype, the pixel data type is set to that type.
|
|
54
|
-
|
|
55
|
-
If ``dtype`` is ``True`` the pixel data type is inherited from the input if it is a NumPy array.
|
|
56
|
-
|
|
57
|
-
If ``dtype`` is not given and:
|
|
58
|
-
|
|
59
|
-
* the input is a NumPy array,the image data type is determined by the dtype of the array:
|
|
60
|
-
|
|
61
|
-
- if floating point, then the Image inherits the dtype of the array
|
|
62
|
-
- if integer, then the Image is assigned the smallest integer dtype that can
|
|
63
|
-
contain the values in the array. If the minimum value is negative, a signed
|
|
64
|
-
integer type is used; otherwise an unsigned type is used.
|
|
65
|
-
|
|
66
|
-
* the input is a list of lists then the image data type is:
|
|
67
|
-
|
|
68
|
-
- float32 if the list contains any floating point values, otherwise
|
|
69
|
-
- the smallest signed or unsigned int that can represent its
|
|
70
|
-
value span.
|
|
71
|
-
|
|
72
|
-
An image can have boolean pixel values which are stored as ``uint8`` values.
|
|
73
|
-
When used in a numerical expression, its values will be cast to integer values
|
|
74
|
-
of 0 or 1 representing False and True respectively.
|
|
75
|
-
|
|
76
|
-
**Color planes**
|
|
77
|
-
|
|
78
|
-
Images can have multiple planes, typically three (representing the
|
|
79
|
-
primary colors red, green and blue) but *any number* is possible. In
|
|
80
|
-
the underlying Numpy array, these planes are identified by an integer
|
|
81
|
-
plane index (the last dimension of the 3D array).
|
|
82
|
-
|
|
83
|
-
Rather than rely on a limiting convention such as planes being in the order
|
|
84
|
-
RGB or BGR, the :class:`Image` contains a dictionary that maps the name of a color plane to
|
|
85
|
-
its index value. The color plane order can be specified as a dict or a string, eg::
|
|
86
|
-
|
|
87
|
-
Image(img, colororder="RGB")
|
|
88
|
-
Image(img, colororder="red:green:blue:alpha")
|
|
89
|
-
Image(img, colororder=dict("R"=2, "G"=1, "B"=0))
|
|
90
|
-
|
|
91
|
-
Image planes can be referenced by their index or by their name, eg.::
|
|
92
|
-
|
|
93
|
-
img.plane(0)
|
|
94
|
-
img.plane("alpha")
|
|
95
|
-
|
|
96
|
-
:seealso: :meth:`colororder` :meth:`colororder_str`
|
|
97
|
-
|
|
98
|
-
**Image domain**
|
|
99
|
-
|
|
100
|
-
An :class:`Image` has a width and height in units of pixels, but for
|
|
101
|
-
some applications it is useful to specify the pixel coordinates in other
|
|
102
|
-
units, perhaps metres, or latitude/longitude angles, or for a spherical image
|
|
103
|
-
as azimuth and colatitude angles. The domain is specified by two 1D arrays
|
|
104
|
-
that map the pixel coordinate to the domain variable.
|
|
105
|
-
|
|
106
|
-
**Binary images**
|
|
107
|
-
|
|
108
|
-
If ``binary`` is True, the image is converted to a binary image, where zero valued
|
|
109
|
-
pixels are set to False and all other values are set to True. To create an
|
|
110
|
-
image where pixels have integer values of 0 and 1 use the ``dtype`` option::
|
|
111
|
-
|
|
112
|
-
Image([[0, 3], [4, 0]]) # pixel values are 0, 3, 4, 0
|
|
113
|
-
Image([[0, 3], [4, 0]], binary=True) # pixel values are: False, True, True, False
|
|
114
|
-
Image([[0, 3], [4, 0]], binary=True, dtype="uint8") # pixel values are 0, 1, 1, 0
|
|
115
|
-
|
|
116
|
-
**Reshaping**
|
|
117
|
-
|
|
118
|
-
Frequently we need to create an image from 1D data, for example::
|
|
119
|
-
|
|
120
|
-
1: Y0 Y1 Y2 ... # (N,)
|
|
121
|
-
2: R0 G0 B0 R1 G1 B1 ... # (3N,)
|
|
122
|
-
|
|
123
|
-
Or a 2D array with one or more rows::
|
|
124
|
-
|
|
125
|
-
3: Y0 Y1 Y2 ... # (1, N)
|
|
126
|
-
|
|
127
|
-
4: R0 G0 B0 R1 G1 B1 ... # (1,3N)
|
|
128
|
-
|
|
129
|
-
5: R0 R1 R2 ... # (3,N)
|
|
130
|
-
G0 G1 G2 ...
|
|
131
|
-
B0 B1 B2 ...
|
|
132
|
-
|
|
133
|
-
Or a 2D array with one or more columns::
|
|
134
|
-
|
|
135
|
-
6: Y0 # (N,1)
|
|
136
|
-
Y1
|
|
137
|
-
Y2
|
|
138
|
-
.
|
|
139
|
-
.
|
|
140
|
-
|
|
141
|
-
7: R0 # (3N,1)
|
|
142
|
-
G0
|
|
143
|
-
B0
|
|
144
|
-
R1
|
|
145
|
-
.
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
8: R0 G0 B0 # (N,3)
|
|
149
|
-
R1 G1 B1
|
|
150
|
-
R2 G2 B2
|
|
151
|
-
.
|
|
152
|
-
.
|
|
153
|
-
|
|
154
|
-
The ``size`` option can be used to reshape the data to the specified size. The number
|
|
155
|
-
of planes is determined from any of: ``colororder``, the third element of
|
|
156
|
-
``size``, or the number of row/columns in the data (formats 5 or 8). For formats
|
|
157
|
-
2, 4 or 7 the number of planes must be given explicitly in ``colororder``, the
|
|
158
|
-
third element of ``size``.
|
|
159
|
-
|
|
160
|
-
:seealso: :meth:`view1d`
|
|
161
|
-
|
|
162
|
-
Example:
|
|
163
|
-
|
|
164
|
-
.. runblock:: pycon
|
|
165
|
-
|
|
166
|
-
>>> from machinevisiontoolbox import Image
|
|
167
|
-
>>> import numpy as np
|
|
168
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
169
|
-
>>> print(img)
|
|
170
|
-
>>> img.print()
|
|
171
|
-
>>> Image(np.array([[1, 2], [3, 4]]))
|
|
172
|
-
>>> Image([[1, 2], [3, 1000]])
|
|
173
|
-
>>> Image([[0.1, 0.2], [0.3, 0.4]])
|
|
174
|
-
>>> Image([[True, False], [False, True]])
|
|
175
|
-
|
|
176
|
-
.. warning:: If an image is constructed from an existing :class:`Image` instance or a Numpy array,
|
|
177
|
-
the encapsulated Numpy array is, by default, a *reference* to the passed image data.
|
|
178
|
-
Use the option ``copy=True`` if you want to copy the data.
|
|
179
|
-
|
|
180
|
-
"""
|
|
181
|
-
|
|
182
|
-
#################### ImageCore.py/Image.__str__
|
|
183
|
-
"""
|
|
184
|
-
Single line summary of image parameters
|
|
185
|
-
|
|
186
|
-
:return: single line summary of image
|
|
187
|
-
:rtype: str
|
|
188
|
-
|
|
189
|
-
Example:
|
|
190
|
-
|
|
191
|
-
.. runblock:: pycon
|
|
192
|
-
|
|
193
|
-
>>> from machinevisiontoolbox import Image
|
|
194
|
-
>>> img = Image.Read('flowers1.png')
|
|
195
|
-
>>> str(img)
|
|
196
|
-
"""
|
|
197
|
-
|
|
198
|
-
#################### ImageCore.py/Image.rprint
|
|
199
|
-
"""
|
|
200
|
-
Print image pixels in compact format and return image
|
|
201
|
-
|
|
202
|
-
:param fmt: format string, defaults to None
|
|
203
|
-
:type fmt: str, optional
|
|
204
|
-
:param separator: value separator, defaults to single space
|
|
205
|
-
:type separator: str, optional
|
|
206
|
-
:param precision: precision for floating point pixel values, defaults to 2
|
|
207
|
-
:type precision: int, optional
|
|
208
|
-
:param header: print image summary header, defaults to True
|
|
209
|
-
:type header: bool, optional
|
|
210
|
-
:param file: file to print to, defaults to None
|
|
211
|
-
:type file: file, optional
|
|
212
|
-
:return: the printed image
|
|
213
|
-
:rtype: :class:`Image`
|
|
214
|
-
|
|
215
|
-
Very compact display of pixel numerical values in grid layout and return the image itself.
|
|
216
|
-
|
|
217
|
-
Example:
|
|
218
|
-
|
|
219
|
-
.. runblock:: pycon
|
|
220
|
-
|
|
221
|
-
>>> from machinevisiontoolbox import Image
|
|
222
|
-
>>> img = Image.Squares(1, size=10).rprint()
|
|
223
|
-
>>> print(img)
|
|
224
|
-
>>> img = Image.Squares(1, size=10, dtype='float').rprint(precision=1, header=True)
|
|
225
|
-
>>> print(img)
|
|
226
|
-
|
|
227
|
-
The function returns the image, which is why we see the image ``repr`` value
|
|
228
|
-
after the printed pixels in this python intrepreter.
|
|
229
|
-
|
|
230
|
-
The `rprint` method is particularly useful in a method chain, for example:
|
|
231
|
-
|
|
232
|
-
.. runblock:: pycon
|
|
233
|
-
|
|
234
|
-
>>> from machinevisiontoolbox import Image
|
|
235
|
-
>>> img = Image.Random(size=3).rprint()
|
|
236
|
-
>>> print(img) # return result of print() is the image itself
|
|
237
|
-
|
|
238
|
-
.. note::
|
|
239
|
-
|
|
240
|
-
- For a boolean image True and False are displayed as 1 and 0
|
|
241
|
-
respectively.
|
|
242
|
-
- For a multiplane images the planes are printed sequentially, along
|
|
243
|
-
with the plane's name.
|
|
244
|
-
|
|
245
|
-
:seealso: :meth:`print` :meth:`Image.strhcat` :meth:`Image.showpixels`
|
|
246
|
-
"""
|
|
247
|
-
|
|
248
|
-
#################### ImageCore.py/Image.print
|
|
249
|
-
"""
|
|
250
|
-
Print image pixels in compact format
|
|
251
|
-
|
|
252
|
-
:param fmt: format string, defaults to None
|
|
253
|
-
:type fmt: str, optional
|
|
254
|
-
:param separator: value separator, defaults to single space
|
|
255
|
-
:type separator: str, optional
|
|
256
|
-
:param precision: precision for floating point pixel values, defaults to 2
|
|
257
|
-
:type precision: int, optional
|
|
258
|
-
:param header: print image summary header, defaults to True
|
|
259
|
-
:type header: bool, optional
|
|
260
|
-
:param file: file to print to, defaults to None
|
|
261
|
-
:type file: file, optional
|
|
262
|
-
:return: the printed image
|
|
263
|
-
:rtype: :class:`Image`
|
|
264
|
-
|
|
265
|
-
Very compact display of pixel numerical values in grid layout.
|
|
266
|
-
|
|
267
|
-
Example:
|
|
268
|
-
|
|
269
|
-
.. runblock:: pycon
|
|
270
|
-
|
|
271
|
-
>>> from machinevisiontoolbox import Image
|
|
272
|
-
>>> img = Image.Squares(1, size=10)
|
|
273
|
-
>>> img.print()
|
|
274
|
-
>>> img = Image.Squares(1, size=10, dtype='float')
|
|
275
|
-
>>> img.print(precision=1, header=True)
|
|
276
|
-
|
|
277
|
-
.. note::
|
|
278
|
-
|
|
279
|
-
- For a boolean image True and False are displayed as 1 and 0
|
|
280
|
-
respectively.
|
|
281
|
-
- For a multiplane images the planes are printed sequentially, along
|
|
282
|
-
with the plane's name.
|
|
283
|
-
|
|
284
|
-
:seealso: :meth:`rprint` :meth:`Image.strhcat` :meth:`Image.showpixels`
|
|
285
|
-
"""
|
|
286
|
-
|
|
287
|
-
#################### ImageCore.py/Image.strhcat
|
|
288
|
-
"""Format several small images concatenated horizontally
|
|
289
|
-
|
|
290
|
-
:param images: one or more images to be formatted horizontally concatenated
|
|
291
|
-
:type images: :class:`Image` instances
|
|
292
|
-
:param widths: number of digits for the formatted array elements, defaults to 1.
|
|
293
|
-
If scalar applies to all images, if list applies to each image.
|
|
294
|
-
:type widths: int or list of ints, optional
|
|
295
|
-
:param arraysep: separator between arrays, defaults to ``" |"``
|
|
296
|
-
:type arraysep: str, optional
|
|
297
|
-
:param labels: list of labels for each array, defaults to None
|
|
298
|
-
:type labels: list of str, optional
|
|
299
|
-
:return: multiline string containing formatted arrays
|
|
300
|
-
:rtype: str
|
|
301
|
-
:raises ValueError: if the arrays have different numbers of rows
|
|
302
|
-
|
|
303
|
-
AUTO_EDIT
|
|
304
|
-
|
|
305
|
-
For image processing this is useful for displaying small test images.
|
|
306
|
-
|
|
307
|
-
The arrays are formatted and concatenated horizontally with a vertical separator.
|
|
308
|
-
Each array has a header row that indicates the column number. Each row has a
|
|
309
|
-
header column that indicates the row number.
|
|
310
|
-
|
|
311
|
-
.. runblock:: pycon
|
|
312
|
-
|
|
313
|
-
>>> from machinevisiontoolbox import Image
|
|
314
|
-
>>> A = Image.Random(size=(5,5), maxval=9)
|
|
315
|
-
>>> print(Image.strhcat(A))
|
|
316
|
-
>>> print(Image.strhcat(A, widths=2))
|
|
317
|
-
>>> B = Image.Random(size=(5,5), maxval=9)
|
|
318
|
-
>>> print(Image.strhcat(A, B))
|
|
319
|
-
>>> print(Image.strhcat(A, B, labels=("A:", "B:")))
|
|
320
|
-
|
|
321
|
-
The number of rows in each image must be the same, but the number of columns can
|
|
322
|
-
vary.
|
|
323
|
-
|
|
324
|
-
:seealso: :meth:`Image.print` :meth:`Image.showpixels` :func:`Image`
|
|
325
|
-
"""
|
|
326
|
-
|
|
327
|
-
#################### ImageCore.py/Image.__repr__
|
|
328
|
-
"""
|
|
329
|
-
Readable representation of image parameters
|
|
330
|
-
|
|
331
|
-
:return: summary of image enclosed in angle brackets
|
|
332
|
-
:rtype: str
|
|
333
|
-
|
|
334
|
-
Example:
|
|
335
|
-
|
|
336
|
-
.. runblock:: pycon
|
|
337
|
-
|
|
338
|
-
>>> from machinevisiontoolbox import Image
|
|
339
|
-
>>> img = Image.Read('flowers1.png')
|
|
340
|
-
>>> img
|
|
341
|
-
"""
|
|
342
|
-
|
|
343
|
-
#################### ImageCore.py/Image.copy
|
|
344
|
-
"""
|
|
345
|
-
Create image copy
|
|
346
|
-
|
|
347
|
-
:param copy: copy the image data
|
|
348
|
-
:type copy: bool
|
|
349
|
-
:return: copy of image
|
|
350
|
-
:rtype: :class:`Image`
|
|
351
|
-
|
|
352
|
-
Create a new :class:`Image` instance which contains a copy of the
|
|
353
|
-
original image data. If ``copy`` is False the new :class:`Image`
|
|
354
|
-
instance contains a reference to the original image data.
|
|
355
|
-
"""
|
|
356
|
-
|
|
357
|
-
#################### ImageCore.py/Image.colororder
|
|
358
|
-
"""
|
|
359
|
-
Set/get color order of image
|
|
360
|
-
|
|
361
|
-
The color order is a dict where the key is the color plane name, eg. 'R'
|
|
362
|
-
and the value is the index of the plane in the 3D pixel value array.
|
|
363
|
-
|
|
364
|
-
Example:
|
|
365
|
-
|
|
366
|
-
.. runblock:: pycon
|
|
367
|
-
|
|
368
|
-
>>> from machinevisiontoolbox import Image
|
|
369
|
-
>>> img = Image.Read('flowers1.png')
|
|
370
|
-
>>> img.colororder
|
|
371
|
-
>>> img.colororder = "BGR"
|
|
372
|
-
>>> img.colororder
|
|
373
|
-
|
|
374
|
-
When setting the color order the value can be any of:
|
|
375
|
-
|
|
376
|
-
* simple string, one plane per character, eg. ``"RGB"``
|
|
377
|
-
* colon separated string, eg. ``"R:G:B"``, ``"L*:a*:b*"``
|
|
378
|
-
* dictionary, eg. ``dict(R=0, G=1, B=2)``
|
|
379
|
-
|
|
380
|
-
For the first two cases the color plane indices are implicit in the
|
|
381
|
-
order in the string.
|
|
382
|
-
|
|
383
|
-
.. note:: Changing the color order does not change the order of the planes
|
|
384
|
-
in the image array, it simply changes their label.
|
|
385
|
-
|
|
386
|
-
:seealso: :meth:`colororder_str` :meth:`colordict` :meth:`plane` :meth:`red` :meth:`green` :meth:`blue`
|
|
387
|
-
"""
|
|
388
|
-
|
|
389
|
-
#################### ImageCore.py/Image._opencv_type_check
|
|
390
|
-
"""
|
|
391
|
-
Check that a NumPy array has a type accepted by an OpenCV function.
|
|
392
|
-
|
|
393
|
-
:param array: array to check
|
|
394
|
-
:type array: np.ndarray
|
|
395
|
-
:param accepted_types: accepted OpenCV type strings
|
|
396
|
-
:type accepted_types: str
|
|
397
|
-
:raises TypeError: if the array dtype or channel count is not accepted by OpenCV
|
|
398
|
-
|
|
399
|
-
Recognised type strings:
|
|
400
|
-
|
|
401
|
-
- Depth strings: ``"CV_8U"``, ``"CV_8S"``, ``"CV_16U"``, ``"CV_16S"``,
|
|
402
|
-
``"CV_32S"``, ``"CV_32F"``, ``"CV_64F"``
|
|
403
|
-
- Channel strings: ``"single-channel"`` (array must be 2D),
|
|
404
|
-
``"multiple-channel"`` (array may be 2D or 3D)
|
|
405
|
-
|
|
406
|
-
Example::
|
|
407
|
-
|
|
408
|
-
Image._opencv_type_check(img, "single-channel", "CV_8U")
|
|
409
|
-
Image._opencv_type_check(img, "multiple-channel", "CV_8U", "CV_16S", "CV_32F")
|
|
410
|
-
"""
|
|
411
|
-
|
|
412
|
-
#################### ImageCore.py/Image.colordict
|
|
413
|
-
"""
|
|
414
|
-
Parse a color order specification
|
|
415
|
-
|
|
416
|
-
:param colororder: order of color channels
|
|
417
|
-
:type colororder: str, dict
|
|
418
|
-
:raises ValueError: ``colororder`` not a string or dict
|
|
419
|
-
:return: dictionary mapping color names to plane indices
|
|
420
|
-
:rtype: dict
|
|
421
|
-
|
|
422
|
-
The color order the value can be given in a variety of forms:
|
|
423
|
-
|
|
424
|
-
* simple string, one plane per character, eg. ``"RGB"``
|
|
425
|
-
* colon separated string, eg. ``"R:G:B"``, ``"L*:a*:b*"``
|
|
426
|
-
* dictionary, eg. ``dict(R=0, G=1, B=2)``
|
|
427
|
-
|
|
428
|
-
Example:
|
|
429
|
-
|
|
430
|
-
.. runblock:: pycon
|
|
431
|
-
|
|
432
|
-
>>> from machinevisiontoolbox import Image
|
|
433
|
-
>>> Image.colordict('RGB')
|
|
434
|
-
>>> Image.colordict('red:green:blue')
|
|
435
|
-
>>> Image.colordict({'L*': 0, 'U*': 1, 'V*': 2})
|
|
436
|
-
|
|
437
|
-
:deprecated: use :meth:`colororder2dict`
|
|
438
|
-
"""
|
|
439
|
-
|
|
440
|
-
#################### ImageCore.py/Image.colororder2dict
|
|
441
|
-
"""
|
|
442
|
-
Parse a color order specification to a color dictionary
|
|
443
|
-
|
|
444
|
-
:param colororder: order of color channels
|
|
445
|
-
:type colororder: str, dict
|
|
446
|
-
:param start: starting index for plane numbering, defaults to 0
|
|
447
|
-
:type start: int, optional
|
|
448
|
-
:raises ValueError: ``colororder`` not a string or dict
|
|
449
|
-
:return: dictionary mapping color names to plane indices
|
|
450
|
-
:rtype: dict
|
|
451
|
-
|
|
452
|
-
The color order the value can be given in a variety of forms:
|
|
453
|
-
|
|
454
|
-
AUTO_EDIT
|
|
455
|
-
|
|
456
|
-
* simple string, one plane per character, eg. ``"RGB"``
|
|
457
|
-
* colon separated string, eg. ``"R:G:B"``, ``"L*:a*:b*"``
|
|
458
|
-
* dictionary, eg. ``dict(R=0, G=1, B=2)``
|
|
459
|
-
|
|
460
|
-
Example:
|
|
461
|
-
|
|
462
|
-
.. runblock:: pycon
|
|
463
|
-
|
|
464
|
-
>>> from machinevisiontoolbox import Image
|
|
465
|
-
>>> Image.colororder2dict('RGB')
|
|
466
|
-
>>> Image.colororder2dict('red:green:blue')
|
|
467
|
-
>>> Image.colororder2dict({'L*': 0, 'U*': 1, 'V*': 2})
|
|
468
|
-
"""
|
|
469
|
-
|
|
470
|
-
#################### ImageCore.py/Image.colordict2list
|
|
471
|
-
"""
|
|
472
|
-
Convert a color dictionary to a list of color plane names
|
|
473
|
-
|
|
474
|
-
:param cdict: dictionary mapping color names to plane indices
|
|
475
|
-
:type cdict: dict
|
|
476
|
-
:return: list of color channels in plane order
|
|
477
|
-
:rtype: list
|
|
478
|
-
|
|
479
|
-
Example:
|
|
480
|
-
|
|
481
|
-
.. runblock:: pycon
|
|
482
|
-
|
|
483
|
-
>>> from machinevisiontoolbox import Image
|
|
484
|
-
>>> Image.colordict2list({'R': 0, 'G': 1, 'B': 2})
|
|
485
|
-
|
|
486
|
-
.. note:: The color planes are sorted by their index value. There is no
|
|
487
|
-
check that the lowest plane index is zero.
|
|
488
|
-
|
|
489
|
-
:seealso: :meth:`colordict2str` :meth:`colororder2dict`
|
|
490
|
-
"""
|
|
491
|
-
|
|
492
|
-
#################### ImageCore.py/Image.colordict2str
|
|
493
|
-
"""
|
|
494
|
-
Convert a color dictionary to a color order string
|
|
495
|
-
|
|
496
|
-
:param cdict: dictionary mapping color names to plane indices
|
|
497
|
-
:type cdict: dict
|
|
498
|
-
:return: color channel names in plane order as a colon-separated string
|
|
499
|
-
:rtype: str
|
|
500
|
-
|
|
501
|
-
Example:
|
|
502
|
-
|
|
503
|
-
.. runblock:: pycon
|
|
504
|
-
|
|
505
|
-
>>> from machinevisiontoolbox import Image
|
|
506
|
-
>>> Image.colordict2str({'R': 0, 'G': 1, 'B': 2})
|
|
507
|
-
|
|
508
|
-
.. note:: The color planes are sorted by their index value. There is no
|
|
509
|
-
check that the lowest plane index is zero.
|
|
510
|
-
|
|
511
|
-
:seealso: :meth:`colordict2list` :meth:`colororder2dict`
|
|
512
|
-
|
|
513
|
-
AUTO_EDIT
|
|
514
|
-
"""
|
|
515
|
-
|
|
516
|
-
#################### ImageCore.py/Image.colororder_str
|
|
517
|
-
"""
|
|
518
|
-
Image color order as a string
|
|
519
|
-
|
|
520
|
-
:return: Image color plane order as a colon separated string.
|
|
521
|
-
:rtype: str
|
|
522
|
-
|
|
523
|
-
Example:
|
|
524
|
-
|
|
525
|
-
.. runblock:: pycon
|
|
526
|
-
|
|
527
|
-
>>> from machinevisiontoolbox import Image
|
|
528
|
-
>>> img = Image.Read('flowers1.png')
|
|
529
|
-
>>> img.colororder_str
|
|
530
|
-
|
|
531
|
-
:seealso: :meth:`colororder`
|
|
532
|
-
"""
|
|
533
|
-
|
|
534
|
-
#################### ImageCore.py/Image.name
|
|
535
|
-
"""
|
|
536
|
-
Set/get image name
|
|
537
|
-
|
|
538
|
-
An image has a string-valued name that can be read and written.
|
|
539
|
-
The name is shown by the Image repr and when images are displayed
|
|
540
|
-
graphically.
|
|
541
|
-
|
|
542
|
-
Example:
|
|
543
|
-
|
|
544
|
-
.. runblock:: pycon
|
|
545
|
-
|
|
546
|
-
>>> from machinevisiontoolbox import Image
|
|
547
|
-
>>> img = Image.Read('flowers1.png')
|
|
548
|
-
>>> img.name[-70:]
|
|
549
|
-
>>> img.name = 'my image'
|
|
550
|
-
>>> img.name
|
|
551
|
-
|
|
552
|
-
.. note:: Images loaded from a file have their name initially set to
|
|
553
|
-
the full file pathname.
|
|
554
|
-
|
|
555
|
-
:seealso: :meth:`Read`
|
|
556
|
-
"""
|
|
557
|
-
|
|
558
|
-
#################### ImageCore.py/Image.isfloat
|
|
559
|
-
"""
|
|
560
|
-
Image has floating point pixel values?
|
|
561
|
-
|
|
562
|
-
:return: True if image has floating point values
|
|
563
|
-
:rtype: bool
|
|
564
|
-
|
|
565
|
-
Example:
|
|
566
|
-
|
|
567
|
-
.. runblock:: pycon
|
|
568
|
-
|
|
569
|
-
>>> from machinevisiontoolbox import Image
|
|
570
|
-
>>> img = Image.Read('flowers1.png')
|
|
571
|
-
>>> img.isfloat
|
|
572
|
-
>>> img = Image.Read('flowers1.png', dtype='float32')
|
|
573
|
-
>>> img.isfloat
|
|
574
|
-
|
|
575
|
-
:seealso: :meth:`isint` :meth:`isbool`
|
|
576
|
-
"""
|
|
577
|
-
|
|
578
|
-
#################### ImageCore.py/Image.isint
|
|
579
|
-
"""
|
|
580
|
-
Image has integer values?
|
|
581
|
-
|
|
582
|
-
:return: True if image has integer pixel values
|
|
583
|
-
:rtype: bool
|
|
584
|
-
|
|
585
|
-
Example:
|
|
586
|
-
|
|
587
|
-
.. runblock:: pycon
|
|
588
|
-
|
|
589
|
-
>>> from machinevisiontoolbox import Image
|
|
590
|
-
>>> img = Image.Read('flowers1.png')
|
|
591
|
-
>>> img.isint
|
|
592
|
-
>>> img = Image.Read('flowers1.png', dtype='float32')
|
|
593
|
-
>>> img.isint
|
|
594
|
-
|
|
595
|
-
:seealso: :meth:`isfloat` :meth:`isbool`
|
|
596
|
-
"""
|
|
597
|
-
|
|
598
|
-
#################### ImageCore.py/Image.isbool
|
|
599
|
-
"""
|
|
600
|
-
Image has bolean values?
|
|
601
|
-
|
|
602
|
-
:return: True if image has boolean pixel values
|
|
603
|
-
:rtype: bool
|
|
604
|
-
|
|
605
|
-
Example:
|
|
606
|
-
|
|
607
|
-
.. runblock:: pycon
|
|
608
|
-
|
|
609
|
-
>>> from machinevisiontoolbox import Image
|
|
610
|
-
>>> img = Image.Read('flowers1.png') > 200
|
|
611
|
-
>>> img.isint
|
|
612
|
-
>>> img.isbool
|
|
613
|
-
|
|
614
|
-
:seealso: :meth:`isint` :meth:`isfloat`
|
|
615
|
-
"""
|
|
616
|
-
|
|
617
|
-
#################### ImageCore.py/Image.dtype
|
|
618
|
-
"""
|
|
619
|
-
Datatype of image
|
|
620
|
-
|
|
621
|
-
:return: NumPy datatype of image
|
|
622
|
-
:rtype: numpy.dtype
|
|
623
|
-
|
|
624
|
-
Example:
|
|
625
|
-
|
|
626
|
-
.. runblock:: pycon
|
|
627
|
-
|
|
628
|
-
>>> from machinevisiontoolbox import Image
|
|
629
|
-
>>> img = Image.Read('flowers1.png')
|
|
630
|
-
>>> img.dtype
|
|
631
|
-
>>> img = Image.Read('flowers1.png', dtype='float32')
|
|
632
|
-
>>> img.dtype
|
|
633
|
-
|
|
634
|
-
:seealso: :meth:`to` :meth:`to_int` :meth:`to_float` :meth:`like` :meth:`cast` :func:`numpy.dtype`
|
|
635
|
-
"""
|
|
636
|
-
|
|
637
|
-
#################### ImageCore.py/Image.numnan
|
|
638
|
-
"""
|
|
639
|
-
Number of NaN pixels in image
|
|
640
|
-
|
|
641
|
-
:return: number of NaN pixels in image
|
|
642
|
-
:rtype: int
|
|
643
|
-
|
|
644
|
-
Example:
|
|
645
|
-
|
|
646
|
-
.. runblock:: pycon
|
|
647
|
-
|
|
648
|
-
>>> from machinevisiontoolbox import Image
|
|
649
|
-
>>> from numpy import nan
|
|
650
|
-
>>> img = Image([[1, 2], [3, nan]], dtype='float32')
|
|
651
|
-
>>> img.numnan
|
|
652
|
-
|
|
653
|
-
:seealso: :meth:`numinf`
|
|
654
|
-
"""
|
|
655
|
-
|
|
656
|
-
#################### ImageCore.py/Image.numinf
|
|
657
|
-
"""
|
|
658
|
-
Number of Inf pixels in image
|
|
659
|
-
|
|
660
|
-
:return: number of Inf pixels in image
|
|
661
|
-
:rtype: int
|
|
662
|
-
|
|
663
|
-
Example:
|
|
664
|
-
|
|
665
|
-
.. runblock:: pycon
|
|
666
|
-
|
|
667
|
-
>>> from machinevisiontoolbox import Image
|
|
668
|
-
>>> from numpy import inf
|
|
669
|
-
>>> img = Image([[1, 2], [3, inf]], dtype='float32')
|
|
670
|
-
>>> img.numinf
|
|
671
|
-
|
|
672
|
-
:seealso: :meth:`numnan`
|
|
673
|
-
"""
|
|
674
|
-
|
|
675
|
-
#################### ImageCore.py/Image.width
|
|
676
|
-
"""
|
|
677
|
-
Image width
|
|
678
|
-
|
|
679
|
-
:return: Width of image in pixels
|
|
680
|
-
:rtype: int
|
|
681
|
-
|
|
682
|
-
Example:
|
|
683
|
-
|
|
684
|
-
.. runblock:: pycon
|
|
685
|
-
|
|
686
|
-
>>> from machinevisiontoolbox import Image
|
|
687
|
-
>>> img = Image.Read('flowers1.png')
|
|
688
|
-
>>> img.width
|
|
689
|
-
|
|
690
|
-
:seealso: :meth:`height` :meth:`size` :meth:`umax`
|
|
691
|
-
"""
|
|
692
|
-
|
|
693
|
-
#################### ImageCore.py/Image.height
|
|
694
|
-
"""
|
|
695
|
-
Image height
|
|
696
|
-
|
|
697
|
-
:return: Height of image in pixels
|
|
698
|
-
:rtype: int
|
|
699
|
-
|
|
700
|
-
Example:
|
|
701
|
-
|
|
702
|
-
.. runblock:: pycon
|
|
703
|
-
|
|
704
|
-
>>> from machinevisiontoolbox import Image
|
|
705
|
-
>>> img = Image.Read('flowers1.png')
|
|
706
|
-
>>> img.height
|
|
707
|
-
|
|
708
|
-
:seealso: :meth:`width` :meth:`size` :meth:`vmax`
|
|
709
|
-
"""
|
|
710
|
-
|
|
711
|
-
#################### ImageCore.py/Image.umax
|
|
712
|
-
"""
|
|
713
|
-
Image maximum u-coordinate
|
|
714
|
-
|
|
715
|
-
:return: Maximum u-coordinate in image in pixels
|
|
716
|
-
:rtype: int
|
|
717
|
-
|
|
718
|
-
Example:
|
|
719
|
-
|
|
720
|
-
.. runblock:: pycon
|
|
721
|
-
|
|
722
|
-
>>> from machinevisiontoolbox import Image
|
|
723
|
-
>>> img = Image.Read('flowers1.png')
|
|
724
|
-
>>> img.umax
|
|
725
|
-
>>> img.width
|
|
726
|
-
|
|
727
|
-
:seealso: :meth:`width`
|
|
728
|
-
"""
|
|
729
|
-
|
|
730
|
-
#################### ImageCore.py/Image.vmax
|
|
731
|
-
"""
|
|
732
|
-
Image maximum v-coordinate
|
|
733
|
-
|
|
734
|
-
:return: Maximum v-coordinate in image in pixels
|
|
735
|
-
:rtype: int
|
|
736
|
-
|
|
737
|
-
Example:
|
|
738
|
-
|
|
739
|
-
.. runblock:: pycon
|
|
740
|
-
|
|
741
|
-
>>> from machinevisiontoolbox import Image
|
|
742
|
-
>>> img = Image.Read('flowers1.png')
|
|
743
|
-
>>> img.vmax
|
|
744
|
-
>>> img.height
|
|
745
|
-
|
|
746
|
-
:seealso: :meth:`height`
|
|
747
|
-
"""
|
|
748
|
-
|
|
749
|
-
#################### ImageCore.py/Image.uspan
|
|
750
|
-
"""
|
|
751
|
-
Linear span of image horizontally
|
|
752
|
-
|
|
753
|
-
:param step: step size, defaults to 1
|
|
754
|
-
:type step: int, optional
|
|
755
|
-
:return: 1D array of values [0 ... width-1]
|
|
756
|
-
:rtype: ndarray(W)
|
|
757
|
-
|
|
758
|
-
Example:
|
|
759
|
-
|
|
760
|
-
.. runblock:: pycon
|
|
761
|
-
|
|
762
|
-
>>> from machinevisiontoolbox import Image
|
|
763
|
-
>>> import numpy as np
|
|
764
|
-
>>> img = Image.Read('flowers1.png')
|
|
765
|
-
>>> with np.printoptions(threshold=10):
|
|
766
|
-
>>> img.uspan()
|
|
767
|
-
|
|
768
|
-
.. note:: If the image has a ``domain`` specified the horizontal
|
|
769
|
-
component of this is returned instead.
|
|
770
|
-
|
|
771
|
-
.. warning:: Computed using :meth:`numpy.arange` and for ``step>1`` the
|
|
772
|
-
maximum coordinate may not be returned.
|
|
773
|
-
|
|
774
|
-
:seealso: :meth:`umax` :meth:`vspan`
|
|
775
|
-
"""
|
|
776
|
-
|
|
777
|
-
#################### ImageCore.py/Image.vspan
|
|
778
|
-
"""
|
|
779
|
-
Linear span of image vertically
|
|
780
|
-
|
|
781
|
-
:param step: step size, defaults to 1
|
|
782
|
-
:type step: int, optional
|
|
783
|
-
:return: 1D array of values [0 ... height-1]
|
|
784
|
-
:rtype: ndarray(H)
|
|
785
|
-
|
|
786
|
-
Example:
|
|
787
|
-
|
|
788
|
-
.. runblock:: pycon
|
|
789
|
-
|
|
790
|
-
>>> from machinevisiontoolbox import Image
|
|
791
|
-
>>> import numpy as np
|
|
792
|
-
>>> img = Image.Read('flowers1.png')
|
|
793
|
-
>>> with np.printoptions(threshold=10):
|
|
794
|
-
>>> img.vspan()
|
|
795
|
-
|
|
796
|
-
.. note:: If the image has a ``domain`` specified the vertical
|
|
797
|
-
component of this is returned instead.
|
|
798
|
-
|
|
799
|
-
.. warning:: Computed using :meth:`numpy.arange` and for ``step>1`` the
|
|
800
|
-
maximum coordinate may not be returned.
|
|
801
|
-
|
|
802
|
-
:seealso: :meth:`vmax` :meth:`uspan`
|
|
803
|
-
"""
|
|
804
|
-
|
|
805
|
-
#################### ImageCore.py/Image.size
|
|
806
|
-
"""
|
|
807
|
-
Image size
|
|
808
|
-
|
|
809
|
-
:return: Size of image (width, height)
|
|
810
|
-
:rtype: tuple
|
|
811
|
-
|
|
812
|
-
Example:
|
|
813
|
-
|
|
814
|
-
.. runblock:: pycon
|
|
815
|
-
|
|
816
|
-
>>> from machinevisiontoolbox import Image
|
|
817
|
-
>>> img = Image.Read('flowers1.png')
|
|
818
|
-
>>> img.size
|
|
819
|
-
|
|
820
|
-
.. note:: The dimensions are in a different order compared to :meth:`shape`.
|
|
821
|
-
|
|
822
|
-
:seealso: :meth:`width` :meth:`height` :meth:`shape`
|
|
823
|
-
"""
|
|
824
|
-
|
|
825
|
-
#################### ImageCore.py/Image.centre
|
|
826
|
-
"""
|
|
827
|
-
Coordinate of centre pixel
|
|
828
|
-
|
|
829
|
-
:return: Coordinate (u,v) of the centre pixel
|
|
830
|
-
:rtype: tuple
|
|
831
|
-
|
|
832
|
-
Example:
|
|
833
|
-
|
|
834
|
-
.. runblock:: pycon
|
|
835
|
-
|
|
836
|
-
>>> from machinevisiontoolbox import Image
|
|
837
|
-
>>> img = Image.Zeros(size=(50,50))
|
|
838
|
-
>>> img.centre
|
|
839
|
-
>>> img = Image.Zeros(size=(51,51))
|
|
840
|
-
>>> img.centre
|
|
841
|
-
|
|
842
|
-
.. note:: If the image has an even dimension the centre will lie
|
|
843
|
-
between pixels.
|
|
844
|
-
|
|
845
|
-
:seealso: :meth:`center` :meth:`centre_int`
|
|
846
|
-
"""
|
|
847
|
-
|
|
848
|
-
#################### ImageCore.py/Image.center
|
|
849
|
-
"""
|
|
850
|
-
Coordinate of center pixel
|
|
851
|
-
|
|
852
|
-
:return: Coordinate (u,v) of the centre pixel
|
|
853
|
-
:rtype: tuple
|
|
854
|
-
|
|
855
|
-
Example:
|
|
856
|
-
|
|
857
|
-
.. runblock:: pycon
|
|
858
|
-
|
|
859
|
-
>>> from machinevisiontoolbox import Image
|
|
860
|
-
>>> img = Image.Zeros(size=(50,50))
|
|
861
|
-
>>> img.center
|
|
862
|
-
>>> img = Image.Zeros(size=(51,51))
|
|
863
|
-
>>> img.center
|
|
864
|
-
|
|
865
|
-
.. note::
|
|
866
|
-
- If the image has an even dimension the centre will lie
|
|
867
|
-
between pixels.
|
|
868
|
-
- Same as ``centre``, just US spelling
|
|
869
|
-
|
|
870
|
-
:seealso: :meth:`center_int`
|
|
871
|
-
"""
|
|
872
|
-
|
|
873
|
-
#################### ImageCore.py/Image.centre_int
|
|
874
|
-
"""
|
|
875
|
-
Coordinate of centre pixel as integer
|
|
876
|
-
|
|
877
|
-
:return: Coordinate (u,v) of the centre pixel
|
|
878
|
-
:rtype: tuple
|
|
879
|
-
|
|
880
|
-
Example:
|
|
881
|
-
|
|
882
|
-
.. runblock:: pycon
|
|
883
|
-
|
|
884
|
-
>>> from machinevisiontoolbox import Image
|
|
885
|
-
>>> img = Image.Zeros(size=(50,50))
|
|
886
|
-
>>> img.centre_int
|
|
887
|
-
>>> img = Image.Zeros(size=(51,51))
|
|
888
|
-
>>> img.centre_int
|
|
889
|
-
|
|
890
|
-
.. note:: If the image has an even dimension the centre coordinate will
|
|
891
|
-
be truncated toward zero.
|
|
892
|
-
|
|
893
|
-
:seealso: :meth:`centre`
|
|
894
|
-
"""
|
|
895
|
-
|
|
896
|
-
#################### ImageCore.py/Image.center_int
|
|
897
|
-
"""
|
|
898
|
-
Coordinate of centre pixel as integer
|
|
899
|
-
|
|
900
|
-
:return: Coordinate (u,v) of the centre pixel
|
|
901
|
-
:rtype: tuple
|
|
902
|
-
|
|
903
|
-
Integer coordinate of centre pixel.
|
|
904
|
-
|
|
905
|
-
Example:
|
|
906
|
-
|
|
907
|
-
.. runblock:: pycon
|
|
908
|
-
|
|
909
|
-
>>> from machinevisiontoolbox import Image
|
|
910
|
-
>>> img = Image.Zeros(size=(50,50))
|
|
911
|
-
>>> img.center_int
|
|
912
|
-
>>> img = Image.Zeros(size=(51,51))
|
|
913
|
-
>>> img.center_int
|
|
914
|
-
|
|
915
|
-
.. note::
|
|
916
|
-
- If the image has an even dimension the centre coordinate will
|
|
917
|
-
be truncated toward zero.
|
|
918
|
-
- Same as ``centre_int``, just US spelling
|
|
919
|
-
|
|
920
|
-
:seealso: :meth:`center`
|
|
921
|
-
"""
|
|
922
|
-
|
|
923
|
-
#################### ImageCore.py/Image.npixels
|
|
924
|
-
"""
|
|
925
|
-
Number of pixels in image plane
|
|
926
|
-
|
|
927
|
-
:return: Number of pixels in image plane: width x height
|
|
928
|
-
:rtype: int
|
|
929
|
-
|
|
930
|
-
.. note:: Number of planes is not considered.
|
|
931
|
-
|
|
932
|
-
Example:
|
|
933
|
-
|
|
934
|
-
.. runblock:: pycon
|
|
935
|
-
|
|
936
|
-
>>> from machinevisiontoolbox import Image
|
|
937
|
-
>>> img = Image.Read('flowers1.png')
|
|
938
|
-
>>> img.npixels
|
|
939
|
-
>>> img.width * img.height
|
|
940
|
-
|
|
941
|
-
:seealso: :meth:`size`
|
|
942
|
-
"""
|
|
943
|
-
|
|
944
|
-
#################### ImageCore.py/Image.shape
|
|
945
|
-
"""
|
|
946
|
-
Image shape
|
|
947
|
-
|
|
948
|
-
:return: Shape of internal NumPy array
|
|
949
|
-
:rtype: 2-tuple, or 3-tuple if color
|
|
950
|
-
|
|
951
|
-
Example:
|
|
952
|
-
|
|
953
|
-
.. runblock:: pycon
|
|
954
|
-
|
|
955
|
-
>>> from machinevisiontoolbox import Image
|
|
956
|
-
>>> img = Image.Read('flowers1.png')
|
|
957
|
-
>>> img.shape
|
|
958
|
-
>>> img = Image.Read('street.png')
|
|
959
|
-
>>> img.shape
|
|
960
|
-
|
|
961
|
-
.. note:: The dimensions are in a different order compared to :meth:`size`.
|
|
962
|
-
|
|
963
|
-
:seealso: :meth:`size` :meth:`nplanes` :meth:`ndim` :meth:`iscolor`
|
|
964
|
-
"""
|
|
965
|
-
|
|
966
|
-
#################### ImageCore.py/Image.ndim
|
|
967
|
-
"""
|
|
968
|
-
Number of image array dimensions
|
|
969
|
-
|
|
970
|
-
:return: number of image dimensions
|
|
971
|
-
:rtype: int
|
|
972
|
-
|
|
973
|
-
Example:
|
|
974
|
-
|
|
975
|
-
.. runblock:: pycon
|
|
976
|
-
|
|
977
|
-
>>> from machinevisiontoolbox import Image
|
|
978
|
-
>>> img = Image.Read('flowers1.png')
|
|
979
|
-
>>> img.ndim
|
|
980
|
-
>>> img = Image.Read('street.png')
|
|
981
|
-
>>> img.ndim
|
|
982
|
-
|
|
983
|
-
:seealso: :meth:`nplanes` :meth:`shape`
|
|
984
|
-
"""
|
|
985
|
-
|
|
986
|
-
#################### ImageCore.py/Image.contains
|
|
987
|
-
"""
|
|
988
|
-
Test if coordinate lies within image
|
|
989
|
-
|
|
990
|
-
:param p: pixel coordinate
|
|
991
|
-
:type p: array_like(2), ndarray(2,N)
|
|
992
|
-
:return: whether pixel coordinate lies within image bounds
|
|
993
|
-
:rtype: bool, ndarray(N)
|
|
994
|
-
|
|
995
|
-
Example:
|
|
996
|
-
|
|
997
|
-
.. runblock:: pycon
|
|
998
|
-
|
|
999
|
-
>>> from machinevisiontoolbox import Image
|
|
1000
|
-
>>> import numpy as np
|
|
1001
|
-
>>> img = Image.Zeros(size=10)
|
|
1002
|
-
>>> img.contains((4,6))
|
|
1003
|
-
>>> img.contains((-1, 7))
|
|
1004
|
-
>>> img.contains(np.array([[4, 6], [-1, 7], [10, 10]]).T)
|
|
1005
|
-
"""
|
|
1006
|
-
|
|
1007
|
-
#################### ImageCore.py/Image.iscolor
|
|
1008
|
-
"""
|
|
1009
|
-
Image has color pixels?
|
|
1010
|
-
|
|
1011
|
-
:return: Image is color
|
|
1012
|
-
:rtype: bool
|
|
1013
|
-
|
|
1014
|
-
:return: number of image dimensions
|
|
1015
|
-
:rtype: int
|
|
1016
|
-
|
|
1017
|
-
Example:
|
|
1018
|
-
|
|
1019
|
-
.. runblock:: pycon
|
|
1020
|
-
|
|
1021
|
-
>>> from machinevisiontoolbox import Image
|
|
1022
|
-
>>> img = Image.Read('flowers1.png')
|
|
1023
|
-
>>> img.iscolor
|
|
1024
|
-
>>> img = Image.Read('street.png')
|
|
1025
|
-
>>> img.iscolor
|
|
1026
|
-
|
|
1027
|
-
:seealso: :meth:`isrgb` :meth:`nplanes`
|
|
1028
|
-
"""
|
|
1029
|
-
|
|
1030
|
-
#################### ImageCore.py/Image.isbgr
|
|
1031
|
-
"""
|
|
1032
|
-
Image has BGR color order?
|
|
1033
|
-
|
|
1034
|
-
:return: Image has BGR color order
|
|
1035
|
-
:rtype: bool
|
|
1036
|
-
|
|
1037
|
-
Example:
|
|
1038
|
-
|
|
1039
|
-
.. runblock:: pycon
|
|
1040
|
-
|
|
1041
|
-
>>> from machinevisiontoolbox import Image
|
|
1042
|
-
>>> img = Image.Read('flowers1.png')
|
|
1043
|
-
>>> img.isbgr
|
|
1044
|
-
|
|
1045
|
-
.. note:: Is False if image is not color.
|
|
1046
|
-
|
|
1047
|
-
:seealso: :meth:`colororder`
|
|
1048
|
-
"""
|
|
1049
|
-
|
|
1050
|
-
#################### ImageCore.py/Image.isrgb
|
|
1051
|
-
"""
|
|
1052
|
-
Image has RGB color order?
|
|
1053
|
-
|
|
1054
|
-
:return: Image has RGB color order
|
|
1055
|
-
:rtype: bool
|
|
1056
|
-
|
|
1057
|
-
Example:
|
|
1058
|
-
|
|
1059
|
-
.. runblock:: pycon
|
|
1060
|
-
|
|
1061
|
-
>>> from machinevisiontoolbox import Image
|
|
1062
|
-
>>> img = Image.Read('flowers1.png')
|
|
1063
|
-
>>> img.isrgb
|
|
1064
|
-
|
|
1065
|
-
.. note:: Is False if image is not color.
|
|
1066
|
-
|
|
1067
|
-
:seealso: :meth:`colororder`
|
|
1068
|
-
"""
|
|
1069
|
-
|
|
1070
|
-
#################### ImageCore.py/Image.to
|
|
1071
|
-
"""
|
|
1072
|
-
Convert image datatype
|
|
1073
|
-
|
|
1074
|
-
:param dtype: Numpy data type
|
|
1075
|
-
:type dtype: str or NumPy dtype
|
|
1076
|
-
:return: image
|
|
1077
|
-
:rtype: :class:`Image`
|
|
1078
|
-
|
|
1079
|
-
Create a new image, same size as input image, with pixels of a different
|
|
1080
|
-
datatype. Integer values are scaled according to the maximum value
|
|
1081
|
-
of the datatype, floating values are in the range 0.0 to 1.0.
|
|
1082
|
-
|
|
1083
|
-
Example:
|
|
1084
|
-
|
|
1085
|
-
.. runblock:: pycon
|
|
1086
|
-
|
|
1087
|
-
>>> from machinevisiontoolbox import Image
|
|
1088
|
-
>>> img = Image.Random(size=3)
|
|
1089
|
-
>>> img.print()
|
|
1090
|
-
>>> img.to('float').print()
|
|
1091
|
-
>>> img = Image.Random(size=3, dtype='float')
|
|
1092
|
-
>>> img.print()
|
|
1093
|
-
>>> img.to('uint8').print()
|
|
1094
|
-
|
|
1095
|
-
:seealso: :meth:`astype` :meth:`to_int` :meth:`to_float`
|
|
1096
|
-
"""
|
|
1097
|
-
|
|
1098
|
-
#################### ImageCore.py/Image.astype
|
|
1099
|
-
"""
|
|
1100
|
-
Cast image datatype
|
|
1101
|
-
|
|
1102
|
-
:param dtype: Numpy data type
|
|
1103
|
-
:type dtype: str or NumPy dtype
|
|
1104
|
-
:return: image
|
|
1105
|
-
:rtype: :class:`Image`
|
|
1106
|
-
|
|
1107
|
-
Create a new image, same size as input image, with pixels of a different
|
|
1108
|
-
datatype. Values are retained, only the datatype is changed.
|
|
1109
|
-
|
|
1110
|
-
Example:
|
|
1111
|
-
|
|
1112
|
-
.. runblock:: pycon
|
|
1113
|
-
|
|
1114
|
-
>>> from machinevisiontoolbox import Image
|
|
1115
|
-
>>> img = Image.Random(size=3)
|
|
1116
|
-
>>> img.print()
|
|
1117
|
-
>>> img.astype('float').print()
|
|
1118
|
-
>>> img = Image.Random(size=3, dtype='float')
|
|
1119
|
-
>>> img.print()
|
|
1120
|
-
>>> img.astype('uint8').print()
|
|
1121
|
-
|
|
1122
|
-
:seealso: :meth:`to`
|
|
1123
|
-
"""
|
|
1124
|
-
|
|
1125
|
-
#################### ImageCore.py/Image.image
|
|
1126
|
-
"""
|
|
1127
|
-
Image as NumPy array
|
|
1128
|
-
|
|
1129
|
-
:return: image as a NumPy array
|
|
1130
|
-
:rtype: ndarray(H,W) or ndarray(H,W,3)
|
|
1131
|
-
|
|
1132
|
-
Return a reference to the encapsulated NumPy array that holds the pixel
|
|
1133
|
-
values.
|
|
1134
|
-
|
|
1135
|
-
Example:
|
|
1136
|
-
|
|
1137
|
-
.. runblock:: pycon
|
|
1138
|
-
|
|
1139
|
-
>>> from machinevisiontoolbox import Image
|
|
1140
|
-
>>> img = Image.Read('flowers1.png')
|
|
1141
|
-
>>> img
|
|
1142
|
-
>>> type(img)
|
|
1143
|
-
>>> type(img.image)
|
|
1144
|
-
|
|
1145
|
-
.. note:: For a color image the color plane order is given by the
|
|
1146
|
-
colororder dictionary.
|
|
1147
|
-
|
|
1148
|
-
.. deprecated:: 1.0.3
|
|
1149
|
-
Use :meth:`array` instead.
|
|
1150
|
-
|
|
1151
|
-
:seealso: :meth:`A` :meth:`colororder`
|
|
1152
|
-
"""
|
|
1153
|
-
|
|
1154
|
-
#################### ImageCore.py/Image.array
|
|
1155
|
-
"""
|
|
1156
|
-
Image as NumPy array
|
|
1157
|
-
|
|
1158
|
-
:return: image as a NumPy array
|
|
1159
|
-
:rtype: ndarray(H,W) or ndarray(H,W,3)
|
|
1160
|
-
|
|
1161
|
-
Return a reference to the encapsulated NumPy array that holds the pixel
|
|
1162
|
-
values.
|
|
1163
|
-
|
|
1164
|
-
Example:
|
|
1165
|
-
|
|
1166
|
-
.. runblock:: pycon
|
|
1167
|
-
|
|
1168
|
-
>>> from machinevisiontoolbox import Image
|
|
1169
|
-
>>> img = Image.Read('flowers1.png')
|
|
1170
|
-
>>> type(img)
|
|
1171
|
-
>>> type(img.array)
|
|
1172
|
-
|
|
1173
|
-
.. note:: For a color image the color plane order is given by the
|
|
1174
|
-
colororder dictionary.
|
|
1175
|
-
|
|
1176
|
-
.. warning:: This property is for accessing the NumPy image data for
|
|
1177
|
-
passing to a NumPy, OpenCV or other function. It is not intended for direct
|
|
1178
|
-
manipulation of the image data -- doing so may make the state of the
|
|
1179
|
-
Image instance inconsistent.
|
|
1180
|
-
|
|
1181
|
-
:seealso: :meth:`array_as` :meth:`rgb` :meth:`bgr` :meth:`colororder`
|
|
1182
|
-
"""
|
|
1183
|
-
|
|
1184
|
-
#################### ImageCore.py/Image.A
|
|
1185
|
-
"""
|
|
1186
|
-
Set/get the NumPy array containing pixel values
|
|
1187
|
-
|
|
1188
|
-
**Getting**
|
|
1189
|
-
|
|
1190
|
-
:return: image as a NumPy array
|
|
1191
|
-
:rtype: ndarray(H,W) or ndarray(H,W,3)
|
|
1192
|
-
|
|
1193
|
-
Return a reference to the encapsulated NumPy array that holds the pixel
|
|
1194
|
-
values.
|
|
1195
|
-
|
|
1196
|
-
**Setting**
|
|
1197
|
-
|
|
1198
|
-
Replace the encapsulated NumPy array with another.
|
|
1199
|
-
|
|
1200
|
-
Example:
|
|
1201
|
-
|
|
1202
|
-
.. runblock:: pycon
|
|
1203
|
-
|
|
1204
|
-
>>> from machinevisiontoolbox import Image
|
|
1205
|
-
>>> import numpy as np
|
|
1206
|
-
>>> img = Image.Read('flowers1.png')
|
|
1207
|
-
>>> img
|
|
1208
|
-
>>> type(img)
|
|
1209
|
-
>>> type(img.A)
|
|
1210
|
-
>>> img.A = np.zeros((50,50))
|
|
1211
|
-
>>> img
|
|
1212
|
-
|
|
1213
|
-
.. deprecated:: 1.0.3
|
|
1214
|
-
Use :meth:`array` instead for accessing the NumPy image data and the
|
|
1215
|
-
:meth:`Image` constructor for creating a new ``Image`` with a different array.
|
|
1216
|
-
|
|
1217
|
-
:seealso: :meth:`array` :meth:`image`
|
|
1218
|
-
"""
|
|
1219
|
-
|
|
1220
|
-
#################### ImageCore.py/Image.rgb
|
|
1221
|
-
"""
|
|
1222
|
-
Image as NumPy array in RGB color order
|
|
1223
|
-
|
|
1224
|
-
:raises ValueError: image is greyscale
|
|
1225
|
-
:return: image as a NumPy array in RGB color order
|
|
1226
|
-
:rtype: ndarray(H,W,3)
|
|
1227
|
-
|
|
1228
|
-
The image is guaranteed to be in RGB order irrespective of current color order.
|
|
1229
|
-
|
|
1230
|
-
:seealso: :meth:`image` :meth:`bgr` :meth:`colororder`
|
|
1231
|
-
"""
|
|
1232
|
-
|
|
1233
|
-
#################### ImageCore.py/Image.bgr
|
|
1234
|
-
"""
|
|
1235
|
-
Image as NumPy array in BGR color order
|
|
1236
|
-
|
|
1237
|
-
:raises ValueError: image is greyscale
|
|
1238
|
-
:return: image as a NumPy array in BGR color order
|
|
1239
|
-
:rtype: ndarray(H,W,3)
|
|
1240
|
-
|
|
1241
|
-
The image is guaranteed to be in BGR (OpenCV standard) order irrespective of current color order.
|
|
1242
|
-
|
|
1243
|
-
:seealso: :meth:`image` :meth:`rgb` :meth:`colororder`
|
|
1244
|
-
"""
|
|
1245
|
-
|
|
1246
|
-
#################### ImageCore.py/Image.to_int
|
|
1247
|
-
"""
|
|
1248
|
-
Image as integer NumPy array
|
|
1249
|
-
|
|
1250
|
-
:param intclass: name of NumPy supported integer class, default is 'uint8'
|
|
1251
|
-
:type intclass: str or NumPy dtype, optional
|
|
1252
|
-
:return: NumPy array with integer values
|
|
1253
|
-
:rtype: ndarray(H,W) or ndarray(H,W,P)
|
|
1254
|
-
|
|
1255
|
-
Return a NumPy array with pixels converted to the integer class
|
|
1256
|
-
``intclass``. For the case where the input image is:
|
|
1257
|
-
|
|
1258
|
-
* a floating point class, the pixel values are scaled from an
|
|
1259
|
-
input range of [0,1] to a range spanning zero to the maximum positive
|
|
1260
|
-
value of the output integer class.
|
|
1261
|
-
* an integer class, then the pixels are scaled and cast to ``intclass``.
|
|
1262
|
-
The scale factor is the ratio of the maximum value of the input and
|
|
1263
|
-
output integer classes.
|
|
1264
|
-
* boolean class, False is mapped to zero and True is mapped to the
|
|
1265
|
-
maximum positive value.
|
|
1266
|
-
|
|
1267
|
-
Example:
|
|
1268
|
-
|
|
1269
|
-
.. runblock:: pycon
|
|
1270
|
-
|
|
1271
|
-
>>> from machinevisiontoolbox import Image
|
|
1272
|
-
>>> img = Image([[5_000, 10_000], [30_000, 60_000]])
|
|
1273
|
-
>>> img
|
|
1274
|
-
>>> img.to_int('uint8')
|
|
1275
|
-
>>> img.to_int('uint32')
|
|
1276
|
-
>>> img = Image([[0.0, 0.3], [0.5, 1.0]])
|
|
1277
|
-
>>> img
|
|
1278
|
-
>>> img.to_int('uint8')
|
|
1279
|
-
>>> img = Image([[False, True], [True, False]])
|
|
1280
|
-
>>> img
|
|
1281
|
-
>>> img.to_int('uint8')
|
|
1282
|
-
>>> img.to_int('uint16')
|
|
1283
|
-
|
|
1284
|
-
.. note:: Works for greyscale or color (arbitrary number of planes) image
|
|
1285
|
-
|
|
1286
|
-
.. deprecated:: 1.0.3
|
|
1287
|
-
Use :meth:`array_as` instead.
|
|
1288
|
-
|
|
1289
|
-
:seealso: :meth:`array_as` :meth:`to_float` :meth:`cast` :meth:`like`
|
|
1290
|
-
"""
|
|
1291
|
-
|
|
1292
|
-
#################### ImageCore.py/Image.to_float
|
|
1293
|
-
"""
|
|
1294
|
-
Image as float NumPy array
|
|
1295
|
-
|
|
1296
|
-
:param floatclass: 'single', 'double', 'float32' [default], 'float64'
|
|
1297
|
-
:type floatclass: str or NumPy dtype
|
|
1298
|
-
:return: NumPy array with floating point values
|
|
1299
|
-
:rtype: ndarray(H,W) or ndarray(H,W,P)
|
|
1300
|
-
|
|
1301
|
-
Return a NumPy array with pixels converted to the floating point class ``floatclass``
|
|
1302
|
-
and the values span the range 0 to 1. For the case where the input image
|
|
1303
|
-
is:
|
|
1304
|
-
|
|
1305
|
-
* an integer class, the pixel values are scaled from an input range
|
|
1306
|
-
spanning zero to the maximum positive value of the integer
|
|
1307
|
-
class to [0.0, 1.0]
|
|
1308
|
-
* a floating class, the pixels are cast to change type but not their
|
|
1309
|
-
value.
|
|
1310
|
-
* boolean class, False is mapped to 0.0 and True is mapped to 1.0.
|
|
1311
|
-
|
|
1312
|
-
Example:
|
|
1313
|
-
|
|
1314
|
-
.. runblock:: pycon
|
|
1315
|
-
|
|
1316
|
-
>>> from machinevisiontoolbox import Image
|
|
1317
|
-
>>> img = Image([[50, 100], [150, 200]])
|
|
1318
|
-
>>> img
|
|
1319
|
-
>>> img.to_float()
|
|
1320
|
-
>>> img = Image([[0.0, 0.3], [0.5, 1.0]])
|
|
1321
|
-
>>> img
|
|
1322
|
-
>>> img.to_float('float64')
|
|
1323
|
-
>>> img = Image([[False, True], [True, False]])
|
|
1324
|
-
>>> img.to_float()
|
|
1325
|
-
|
|
1326
|
-
.. note:: Works for greyscale or color (arbitrary number of planes) image
|
|
1327
|
-
|
|
1328
|
-
.. deprecated:: 1.0.3
|
|
1329
|
-
Use :meth:`array_as` instead.
|
|
1330
|
-
|
|
1331
|
-
:seealso: :meth:`array_as` :meth:`to_int` :meth:`cast` :meth:`like`
|
|
1332
|
-
"""
|
|
1333
|
-
|
|
1334
|
-
#################### ImageCore.py/Image.array_as
|
|
1335
|
-
"""
|
|
1336
|
-
Convert Image to NumPy array of specified type
|
|
1337
|
-
|
|
1338
|
-
:param dtype: data type of the output array
|
|
1339
|
-
:type dtype: str or np.dtype
|
|
1340
|
-
:return: NumPy array with specified type
|
|
1341
|
-
:rtype: ndarray(H,W) or ndarray(H,W,P)
|
|
1342
|
-
|
|
1343
|
-
Return a NumPy array with pixels converted to the specified data type.
|
|
1344
|
-
|
|
1345
|
-
========= ======================================== ====================================
|
|
1346
|
-
Input Output int Output float
|
|
1347
|
-
========= ======================================== ====================================
|
|
1348
|
-
float scaled [-1,1] → [min_int, max_int] cast, values unchanged
|
|
1349
|
-
int scaled by max_int_output/max_int_input scaled [min_int, max_int] → [-1, 1]
|
|
1350
|
-
uint scaled by max_int_output/max_int_input scaled [0, max_int] → [0, 1]
|
|
1351
|
-
bool False → 0, True → max_int False → 0.0, True → 1.0
|
|
1352
|
-
========= ======================================== ====================================
|
|
1353
|
-
|
|
1354
|
-
Example:
|
|
1355
|
-
|
|
1356
|
-
.. runblock:: pycon
|
|
1357
|
-
|
|
1358
|
-
>>> from machinevisiontoolbox import Image
|
|
1359
|
-
>>> img = Image([[5_000, 10_000], [30_000, 60_000]]) # uint16 image
|
|
1360
|
-
>>> img
|
|
1361
|
-
>>> img.array_as('uint8')
|
|
1362
|
-
>>> img.array_as('uint32')
|
|
1363
|
-
>>> img.array_as('float')
|
|
1364
|
-
>>> img = Image([[0.0, 0.3], [0.5, 1.0]])
|
|
1365
|
-
>>> img
|
|
1366
|
-
>>> img.array_as('uint8')
|
|
1367
|
-
>>> img = Image([[False, True], [True, False]])
|
|
1368
|
-
>>> img
|
|
1369
|
-
>>> img.array_int('uint8')
|
|
1370
|
-
>>> img.array_int('float')
|
|
1371
|
-
|
|
1372
|
-
.. note:: Works for greyscale or color (arbitrary number of planes) image
|
|
1373
|
-
|
|
1374
|
-
.. warning:: This method assumes that all integer values are unsigned.
|
|
1375
|
-
|
|
1376
|
-
:seealso: :meth:`array` :func:`array_float` :meth:`cast` :meth:`like`
|
|
1377
|
-
"""
|
|
1378
|
-
|
|
1379
|
-
#################### ImageCore.py/Image.cast
|
|
1380
|
-
"""
|
|
1381
|
-
Cast value to same type as image
|
|
1382
|
-
|
|
1383
|
-
:param value: value to cast
|
|
1384
|
-
:type value: scalar, ndarray
|
|
1385
|
-
:return: value cast to same type as image
|
|
1386
|
-
:rtype: numpy type, ndarray
|
|
1387
|
-
|
|
1388
|
-
The value, scalar or integer, is **cast** to the same type as the image.
|
|
1389
|
-
The result has the same numeric value, but the type is changed.
|
|
1390
|
-
|
|
1391
|
-
Example:
|
|
1392
|
-
|
|
1393
|
-
.. runblock:: pycon
|
|
1394
|
-
|
|
1395
|
-
>>> from machinevisiontoolbox import Image
|
|
1396
|
-
>>> img = Image.Read('flowers1.png')
|
|
1397
|
-
>>> x = img.cast(12.5)
|
|
1398
|
-
>>> x
|
|
1399
|
-
>>> type(x)
|
|
1400
|
-
|
|
1401
|
-
.. note:: Scalars are cast to NumPy types not native Python types.
|
|
1402
|
-
|
|
1403
|
-
:seealso: :meth:`like`
|
|
1404
|
-
"""
|
|
1405
|
-
|
|
1406
|
-
#################### ImageCore.py/Image.like
|
|
1407
|
-
"""
|
|
1408
|
-
Convert value to the same type as image
|
|
1409
|
-
|
|
1410
|
-
:param value: scalar or NumPy array
|
|
1411
|
-
:type value: scalar, ndarray
|
|
1412
|
-
:param maxint: maximum integer value for an integer image, defaults to
|
|
1413
|
-
maximum positive value of the class
|
|
1414
|
-
:type maxint: int, optional
|
|
1415
|
-
:raises ValueError: [description]
|
|
1416
|
-
:return: converted value
|
|
1417
|
-
:rtype: NumPy type
|
|
1418
|
-
|
|
1419
|
-
The value, scalar or integer, is **converted** to the same type as the
|
|
1420
|
-
image. The result is optionally rescaled and cast:
|
|
1421
|
-
|
|
1422
|
-
* Float to float: values are cast
|
|
1423
|
-
* Float to int: values in the interval [0, 1] are scaled to the interval
|
|
1424
|
-
[0, ``maxint``] and then cast
|
|
1425
|
-
* Int to float: values in the interval [0, ``maxint``] are scaled to the
|
|
1426
|
-
interval [0, 1] and then cast.
|
|
1427
|
-
* Int to int: values are scaled and cast.
|
|
1428
|
-
|
|
1429
|
-
.. warning:: For integer to integer conversion, integer values greater
|
|
1430
|
-
than the maximum value of the destination class are wrapped not
|
|
1431
|
-
clipped.
|
|
1432
|
-
|
|
1433
|
-
Example:
|
|
1434
|
-
|
|
1435
|
-
.. runblock:: pycon
|
|
1436
|
-
|
|
1437
|
-
>>> from machinevisiontoolbox import Image
|
|
1438
|
-
>>> img = Image.Read('flowers1.png')
|
|
1439
|
-
>>> img.like(0.5)
|
|
1440
|
-
|
|
1441
|
-
:seealso: :meth:`cast` :meth:`to_int` :meth:`to_float`
|
|
1442
|
-
|
|
1443
|
-
"""
|
|
1444
|
-
|
|
1445
|
-
#################### ImageCore.py/Image.minval
|
|
1446
|
-
"""
|
|
1447
|
-
Minimum value of image datatype
|
|
1448
|
-
|
|
1449
|
-
:return: Minimum value
|
|
1450
|
-
:rtype: int or float
|
|
1451
|
-
|
|
1452
|
-
For the datatype of the image, return its minimum possible value
|
|
1453
|
-
|
|
1454
|
-
Example:
|
|
1455
|
-
|
|
1456
|
-
.. runblock:: pycon
|
|
1457
|
-
|
|
1458
|
-
>>> from machinevisiontoolbox import Image
|
|
1459
|
-
>>> img = Image.Zeros(size=20, dtype='float32')
|
|
1460
|
-
>>> img.minval
|
|
1461
|
-
>>> img = Image.Zeros(size=20, dtype='uint8')
|
|
1462
|
-
>>> img.minval
|
|
1463
|
-
|
|
1464
|
-
:seealso: :meth:`maxval`
|
|
1465
|
-
"""
|
|
1466
|
-
|
|
1467
|
-
#################### ImageCore.py/Image.maxval
|
|
1468
|
-
"""
|
|
1469
|
-
Maximum value of image datatype
|
|
1470
|
-
|
|
1471
|
-
:return: Maximum value
|
|
1472
|
-
:rtype: int or float
|
|
1473
|
-
|
|
1474
|
-
For the datatype of the image, return its maximum possible value
|
|
1475
|
-
|
|
1476
|
-
Example:
|
|
1477
|
-
|
|
1478
|
-
.. runblock:: pycon
|
|
1479
|
-
|
|
1480
|
-
>>> from machinevisiontoolbox import Image
|
|
1481
|
-
>>> img = Image.Zeros(size=20, dtype='float32')
|
|
1482
|
-
>>> img.maxval
|
|
1483
|
-
>>> img = Image.Zeros(size=20, dtype='uint8')
|
|
1484
|
-
>>> img.maxval
|
|
1485
|
-
|
|
1486
|
-
:seealso: :meth:`minval`
|
|
1487
|
-
"""
|
|
1488
|
-
|
|
1489
|
-
#################### ImageCore.py/Image.true
|
|
1490
|
-
"""
|
|
1491
|
-
True value for logical image
|
|
1492
|
-
|
|
1493
|
-
:return: Value used as true
|
|
1494
|
-
:rtype: int or float
|
|
1495
|
-
|
|
1496
|
-
The true value is 1.0 for a floating point image and maximum integer
|
|
1497
|
-
value for an integer value.
|
|
1498
|
-
|
|
1499
|
-
Example:
|
|
1500
|
-
|
|
1501
|
-
.. runblock:: pycon
|
|
1502
|
-
|
|
1503
|
-
>>> from machinevisiontoolbox import Image
|
|
1504
|
-
>>> img = Image.Zeros(size=20, dtype='float32')
|
|
1505
|
-
>>> img.true
|
|
1506
|
-
>>> img = Image.Zeros(size=20, dtype='uint8')
|
|
1507
|
-
>>> img.true
|
|
1508
|
-
|
|
1509
|
-
:seealso: :meth:`false` :meth:`maxval`
|
|
1510
|
-
"""
|
|
1511
|
-
|
|
1512
|
-
#################### ImageCore.py/Image.false
|
|
1513
|
-
"""
|
|
1514
|
-
False value for logical image
|
|
1515
|
-
|
|
1516
|
-
:return: Value used as true
|
|
1517
|
-
:rtype: int or float
|
|
1518
|
-
|
|
1519
|
-
The false value is 0.0 for a floating point image and 0
|
|
1520
|
-
value for an integer value.
|
|
1521
|
-
|
|
1522
|
-
Example:
|
|
1523
|
-
|
|
1524
|
-
.. runblock:: pycon
|
|
1525
|
-
|
|
1526
|
-
>>> from machinevisiontoolbox import Image
|
|
1527
|
-
>>> img = Image.Zeros(size=20, dtype='float32')
|
|
1528
|
-
>>> img.false
|
|
1529
|
-
>>> img = Image.Zeros(size=20, dtype='uint8')
|
|
1530
|
-
>>> img.false
|
|
1531
|
-
|
|
1532
|
-
:seealso: :meth:`true`
|
|
1533
|
-
"""
|
|
1534
|
-
|
|
1535
|
-
#################### ImageCore.py/Image.nplanes
|
|
1536
|
-
"""
|
|
1537
|
-
Number of color planes
|
|
1538
|
-
|
|
1539
|
-
:return: Number of color planes, or None if image is empty
|
|
1540
|
-
:rtype: int
|
|
1541
|
-
|
|
1542
|
-
For a 2D or greyscale image this is one, otherwise it is the third
|
|
1543
|
-
dimension of the image.
|
|
1544
|
-
|
|
1545
|
-
Example:
|
|
1546
|
-
|
|
1547
|
-
.. runblock:: pycon
|
|
1548
|
-
|
|
1549
|
-
>>> from machinevisiontoolbox import Image
|
|
1550
|
-
>>> img = Image.Read('street.png')
|
|
1551
|
-
>>> img.nplanes
|
|
1552
|
-
>>> img = Image.Read('flowers1.png')
|
|
1553
|
-
>>> img.nplanes
|
|
1554
|
-
|
|
1555
|
-
.. note:: A greyscale image is stored internally as a 2D NumPy array
|
|
1556
|
-
which has zero planes, but ``nplanes`` will return 1 in that case.
|
|
1557
|
-
|
|
1558
|
-
:seealso: :meth:`iscolor` :meth:`shape` :meth:`ndim`
|
|
1559
|
-
"""
|
|
1560
|
-
|
|
1561
|
-
#################### ImageCore.py/Image.planes
|
|
1562
|
-
"""
|
|
1563
|
-
Iterator for image planes
|
|
1564
|
-
|
|
1565
|
-
:return out: image containing a single plane
|
|
1566
|
-
:rtype: :class:`Image`
|
|
1567
|
-
|
|
1568
|
-
Iterator that returns sequential image planes.
|
|
1569
|
-
|
|
1570
|
-
Example:
|
|
1571
|
-
|
|
1572
|
-
.. runblock:: pycon
|
|
1573
|
-
|
|
1574
|
-
>>> from machinevisiontoolbox import Image
|
|
1575
|
-
>>> img = Image.Read("flowers4.png") # in BGR order
|
|
1576
|
-
>>> for plane in img.planes():
|
|
1577
|
-
>>> print(plane)
|
|
1578
|
-
"""
|
|
1579
|
-
|
|
1580
|
-
#################### ImageCore.py/Image.plane
|
|
1581
|
-
"""
|
|
1582
|
-
Extract plane(s) from color image
|
|
1583
|
-
|
|
1584
|
-
:param planes: planes to extract
|
|
1585
|
-
:type planes: int, list, str
|
|
1586
|
-
:raises ValueError: if image is not color
|
|
1587
|
-
:return out: image containing only the selected planes
|
|
1588
|
-
:rtype: :class:`Image`
|
|
1589
|
-
|
|
1590
|
-
Create a new image from the selected planes of the image.
|
|
1591
|
-
|
|
1592
|
-
Example:
|
|
1593
|
-
|
|
1594
|
-
.. runblock:: pycon
|
|
1595
|
-
|
|
1596
|
-
>>> from machinevisiontoolbox import Image
|
|
1597
|
-
>>> img = Image.Read("flowers4.png") # in BGR order
|
|
1598
|
-
>>> img.colororder_str
|
|
1599
|
-
>>> img.nplanes
|
|
1600
|
-
>>> red = img.plane(0) # red plane
|
|
1601
|
-
>>> red
|
|
1602
|
-
>>> red.iscolor
|
|
1603
|
-
>>> red.nplanes
|
|
1604
|
-
>>> green_blue = img.plane('G:B') # green and blue planes
|
|
1605
|
-
>>> green_blue
|
|
1606
|
-
>>> green_blue.iscolor
|
|
1607
|
-
>>> green_blue.nplanes
|
|
1608
|
-
>>> red_blue = img.plane([0, 2]) # blue and red planes
|
|
1609
|
-
>>> red_blue
|
|
1610
|
-
|
|
1611
|
-
.. note::
|
|
1612
|
-
|
|
1613
|
-
- This can also be performed using the overloaded ``__getitem__``
|
|
1614
|
-
operator.
|
|
1615
|
-
- To select more than one plane, use either a sequence of integers or a string
|
|
1616
|
-
of colon separated plane names.
|
|
1617
|
-
- For a single-plane image the index must be zero.
|
|
1618
|
-
|
|
1619
|
-
:seealso: :meth:`red` :meth:`green` :meth:`blue` :meth:``__getitem__``
|
|
1620
|
-
"""
|
|
1621
|
-
|
|
1622
|
-
#################### ImageCore.py/Image.__getitem__
|
|
1623
|
-
"""
|
|
1624
|
-
Return pixel value or slice from image
|
|
1625
|
-
|
|
1626
|
-
:param keys: slices to extract
|
|
1627
|
-
:type keys: int, str, tuple of int or slice
|
|
1628
|
-
:return: slice of image
|
|
1629
|
-
:rtype: :class:`Image`
|
|
1630
|
-
|
|
1631
|
-
This is a Swiss-army knife method for accessing subregions of an ``Image``
|
|
1632
|
-
by uv-region and/or plane. A ``key`` can be:
|
|
1633
|
-
|
|
1634
|
-
- a 2-tuple of integers, eg. ``img[u,v]``, return this pixel as a scalar. If the image has
|
|
1635
|
-
multiple planes, the result is an ndarray over planes.
|
|
1636
|
-
- a 3-tuple of integers, eg, ``img[u,v,p]``, for a multiplane image return this pixel from
|
|
1637
|
-
specified plane as a scalar.
|
|
1638
|
-
- a 2-tuple containing at least one slice object, eg. ``img[100:110, 200:300]``, return this
|
|
1639
|
-
region as an ``Image``. If the image has multiple planes, the result is a multiplane
|
|
1640
|
-
``Image``.
|
|
1641
|
-
- a 3-tuple containing at least one slice objects, return this region of uv and planes as an
|
|
1642
|
-
``Image`` with one or more planes.
|
|
1643
|
-
- an int, return this plane as an ``Image``.
|
|
1644
|
-
- a string, return this named plane or planes as an ``Image``.
|
|
1645
|
-
|
|
1646
|
-
Example:
|
|
1647
|
-
|
|
1648
|
-
.. runblock:: pycon
|
|
1649
|
-
|
|
1650
|
-
>>> from machinevisiontoolbox import Image
|
|
1651
|
-
>>> img = Image.Read("flowers4.png") # in RGB order
|
|
1652
|
-
>>> red = img[0] # red plane
|
|
1653
|
-
>>> red # greyscale image
|
|
1654
|
-
>>> green = img["G"]
|
|
1655
|
-
>>> green # greyscale image
|
|
1656
|
-
>>> roi = img[100:200, 300:400]
|
|
1657
|
-
>>> roi # color image
|
|
1658
|
-
>>> roi = img[100:200, 300:400, 1:]
|
|
1659
|
-
>>> roi # 2-plane color image
|
|
1660
|
-
>>> roi = img[100, :] # column 100
|
|
1661
|
-
>>> roi # color image
|
|
1662
|
-
>>> pix = img[100, 200, 1] # green pixel at (100,200) as scalar
|
|
1663
|
-
>>> pix
|
|
1664
|
-
>>> pix = img[100, 200] # RGB vector at (100,200) as ndarray
|
|
1665
|
-
>>> pix
|
|
1666
|
-
|
|
1667
|
-
.. note:: If the result is a single row or column the result is a 1xn or nx1
|
|
1668
|
-
``Image`` instance. If the result is a single plane the result is a
|
|
1669
|
-
greyscale image.
|
|
1670
|
-
|
|
1671
|
-
.. note:: Indexing pixel values this way is slow, use :meth:`pixel(u,v)` for faster
|
|
1672
|
-
access, or ``img.A[v,u]`` for direct access to the underlying NumPy array.
|
|
1673
|
-
|
|
1674
|
-
.. warning:: The order of the indices is column, row and plane. This
|
|
1675
|
-
is the opposite of the order used for NumPy index on the underlying
|
|
1676
|
-
array. It is consistent with the column-first convention used across the
|
|
1677
|
-
Toolbox and is consistent with the :math:`(u,v)` coordinate system for images.
|
|
1678
|
-
|
|
1679
|
-
.. versionadded:: 1.0.0
|
|
1680
|
-
The order of the indices changed to column, row, plane. Previously
|
|
1681
|
-
it was row, column, plane.
|
|
1682
|
-
|
|
1683
|
-
:seealso: :meth:`red` :meth:`green` :meth:`blue` :meth:`plane` :meth:`roi` :meth:`pixel`
|
|
1684
|
-
"""
|
|
1685
|
-
|
|
1686
|
-
#################### ImageCore.py/Image.pixel
|
|
1687
|
-
"""
|
|
1688
|
-
Return pixel value
|
|
1689
|
-
|
|
1690
|
-
:param u: column coordinate
|
|
1691
|
-
:type u: int
|
|
1692
|
-
:param v: row coordinate
|
|
1693
|
-
:type v: int
|
|
1694
|
-
:return: pixel value
|
|
1695
|
-
:rtype: int, float or ndarray
|
|
1696
|
-
|
|
1697
|
-
Return the specified pixel. If the image has multiple planes, the result is a vector over planes.
|
|
1698
|
-
|
|
1699
|
-
.. note:: This method is faster than the more general :meth:`__getitem__`
|
|
1700
|
-
for the individual pixel case.
|
|
1701
|
-
|
|
1702
|
-
.. warning:: The order of the indices is column, row and plane. This
|
|
1703
|
-
is the opposite of the order used for NumPy index on the underlying
|
|
1704
|
-
array. It is consistent with the column-first convention used across the
|
|
1705
|
-
Toolbox and is consistent with the :math:`(u,v)` coordinate system for images.
|
|
1706
|
-
|
|
1707
|
-
Example:
|
|
1708
|
-
|
|
1709
|
-
.. runblock:: pycon
|
|
1710
|
-
|
|
1711
|
-
>>> from machinevisiontoolbox import Image
|
|
1712
|
-
>>> img = Image.Read("flowers4.png", mono=True)
|
|
1713
|
-
>>> pix = img.pixel(100, 200)
|
|
1714
|
-
>>> pix # grey scale pixel value
|
|
1715
|
-
>>> img = Image.Read("flowers4.png")
|
|
1716
|
-
>>> pix = img.pixel(100, 200)
|
|
1717
|
-
>>> pix # color pixel value (R, G, B)
|
|
1718
|
-
|
|
1719
|
-
:seealso: :meth:`__getitem__` :meth:`roi`
|
|
1720
|
-
"""
|
|
1721
|
-
|
|
1722
|
-
#################### ImageCore.py/Image.pixels_mask
|
|
1723
|
-
"""
|
|
1724
|
-
Return pixel values at locations specified by a mask
|
|
1725
|
-
|
|
1726
|
-
:param mask: the selection mask as either non-zero pixels in a 2D image or the area covered by a polygon or list of polygons
|
|
1727
|
-
:type mask: :class:`Image`, a single :class:`Polygon2` or a list of :class:`Polygon2`
|
|
1728
|
-
:param coords: include pixel coordinates in output, defaults to False
|
|
1729
|
-
:type coords: bool, optional
|
|
1730
|
-
:param return_mask: also return the mask as an Image, defaults to False
|
|
1731
|
-
:type return_mask: bool, optional
|
|
1732
|
-
:return: array of pixel values and optionally coordinates of pixels selected by the mask, optionally also the mask as an Image
|
|
1733
|
-
:rtype: :class:`Array2d`, :class:`Array2d` and :class:`Image`
|
|
1734
|
-
|
|
1735
|
-
For an image with P planes and a mask that selects N pixels, return an PxN array
|
|
1736
|
-
of pixel values. If ``coords`` is True, the result is an (P+2)xN array where
|
|
1737
|
-
the first two rows are the u and v coordinates of the selected pixels.
|
|
1738
|
-
|
|
1739
|
-
Example:
|
|
1740
|
-
|
|
1741
|
-
.. runblock:: pycon
|
|
1742
|
-
|
|
1743
|
-
>>> from machinevisiontoolbox import Image
|
|
1744
|
-
>>> from spatialmath import Polygon2
|
|
1745
|
-
>>> img = Image.Read("flowers4.png")
|
|
1746
|
-
>>> polygon = Polygon2([(300, 400), (360, 400), (330, 450)], close=True)
|
|
1747
|
-
>>> pixels = img.pixels_mask(polygon, coords=True)
|
|
1748
|
-
>>> pixels.shape
|
|
1749
|
-
>>> pixels[:,:5] # first 5 pixels, with coordinates
|
|
1750
|
-
|
|
1751
|
-
:seealso: :meth:`pixel` :meth:`__getitem__` :meth:`roi`
|
|
1752
|
-
"""
|
|
1753
|
-
|
|
1754
|
-
#################### ImageCore.py/Image.red
|
|
1755
|
-
"""
|
|
1756
|
-
Extract the red plane of a color image
|
|
1757
|
-
|
|
1758
|
-
:raises ValueError: if image is not color
|
|
1759
|
-
:return out: greyscale image representing the red image plane
|
|
1760
|
-
:rtype: :class:`Image`
|
|
1761
|
-
|
|
1762
|
-
Example:
|
|
1763
|
-
|
|
1764
|
-
.. runblock:: pycon
|
|
1765
|
-
|
|
1766
|
-
>>> from machinevisiontoolbox import Image
|
|
1767
|
-
>>> img = Image.Read("flowers4.png")
|
|
1768
|
-
>>> red = img.red() # red plane
|
|
1769
|
-
>>> red.disp()
|
|
1770
|
-
>>> red
|
|
1771
|
-
>>> red.iscolor
|
|
1772
|
-
|
|
1773
|
-
.. plot::
|
|
1774
|
-
|
|
1775
|
-
from machinevisiontoolbox import Image
|
|
1776
|
-
Image.Read("flowers4.png").red().disp()
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
:seealso: :meth:`plane` :meth:`green` :meth:`blue`
|
|
1780
|
-
"""
|
|
1781
|
-
|
|
1782
|
-
#################### ImageCore.py/Image.green
|
|
1783
|
-
"""
|
|
1784
|
-
Extract the green plane of a color image
|
|
1785
|
-
|
|
1786
|
-
:raises ValueError: if image is not color
|
|
1787
|
-
:return out: greyscale image representing the green image plane
|
|
1788
|
-
:rtype: :class:`Image`
|
|
1789
|
-
|
|
1790
|
-
Example:
|
|
1791
|
-
|
|
1792
|
-
.. runblock:: pycon
|
|
1793
|
-
|
|
1794
|
-
>>> from machinevisiontoolbox import Image
|
|
1795
|
-
>>> img = Image.Read("flowers4.png")
|
|
1796
|
-
>>> green = img.green() # green plane
|
|
1797
|
-
>>> green.disp()
|
|
1798
|
-
>>> green
|
|
1799
|
-
>>> green.iscolor
|
|
1800
|
-
|
|
1801
|
-
.. plot::
|
|
1802
|
-
|
|
1803
|
-
from machinevisiontoolbox import Image
|
|
1804
|
-
Image.Read("flowers4.png").green().disp()
|
|
1805
|
-
|
|
1806
|
-
:seealso: :meth:`plane` :meth:`red` :meth:`blue`
|
|
1807
|
-
"""
|
|
1808
|
-
|
|
1809
|
-
#################### ImageCore.py/Image.blue
|
|
1810
|
-
"""
|
|
1811
|
-
Extract the blue plane of a color image
|
|
1812
|
-
|
|
1813
|
-
:raises ValueError: if image is not color
|
|
1814
|
-
:return out: greyscale image representing the blue image plane
|
|
1815
|
-
:rtype: :class:`Image`
|
|
1816
|
-
|
|
1817
|
-
Example:
|
|
1818
|
-
|
|
1819
|
-
.. runblock:: pycon
|
|
1820
|
-
|
|
1821
|
-
>>> from machinevisiontoolbox import Image
|
|
1822
|
-
>>> img = Image.Read("flowers4.png")
|
|
1823
|
-
>>> blue = img.blue() # blue plane
|
|
1824
|
-
>>> blue.disp()
|
|
1825
|
-
>>> blue
|
|
1826
|
-
>>> blue.iscolor
|
|
1827
|
-
|
|
1828
|
-
.. plot::
|
|
1829
|
-
|
|
1830
|
-
from machinevisiontoolbox import Image
|
|
1831
|
-
Image.Read("flowers4.png").blue().disp()
|
|
1832
|
-
|
|
1833
|
-
:seealso: :meth:`plane` :meth:`red` :meth:`green`
|
|
1834
|
-
"""
|
|
1835
|
-
|
|
1836
|
-
#################### ImageCore.py/Image.__mul__
|
|
1837
|
-
"""
|
|
1838
|
-
Overloaded ``*`` operator
|
|
1839
|
-
|
|
1840
|
-
:return: element-wise product of images
|
|
1841
|
-
:rtype: :class:`Image`
|
|
1842
|
-
|
|
1843
|
-
Compute the product of an Image with another image or a scalar.
|
|
1844
|
-
Supports:
|
|
1845
|
-
|
|
1846
|
-
* image ``*`` image, element-wise
|
|
1847
|
-
* scalar ``*`` image
|
|
1848
|
-
* image ``*`` scalar
|
|
1849
|
-
|
|
1850
|
-
Example:
|
|
1851
|
-
|
|
1852
|
-
.. runblock:: pycon
|
|
1853
|
-
|
|
1854
|
-
>>> from machinevisiontoolbox import Image
|
|
1855
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
1856
|
-
>>> z = img * img
|
|
1857
|
-
>>> z.array
|
|
1858
|
-
>>> z = 2 * img
|
|
1859
|
-
>>> z.array
|
|
1860
|
-
|
|
1861
|
-
..warning:: Values will be wrapped not clipped to the range of the
|
|
1862
|
-
pixel datatype.
|
|
1863
|
-
"""
|
|
1864
|
-
|
|
1865
|
-
#################### ImageCore.py/Image.__imul__
|
|
1866
|
-
"""
|
|
1867
|
-
Overloaded in-place ``*=`` operator
|
|
1868
|
-
|
|
1869
|
-
:return: self, modified in place
|
|
1870
|
-
:rtype: :class:`Image`
|
|
1871
|
-
|
|
1872
|
-
Multiply an Image in place by another image or a scalar.
|
|
1873
|
-
|
|
1874
|
-
:seealso: :meth:`__mul__`
|
|
1875
|
-
"""
|
|
1876
|
-
|
|
1877
|
-
#################### ImageCore.py/Image.__pow__
|
|
1878
|
-
"""
|
|
1879
|
-
Overloaded ``**`` operator
|
|
1880
|
-
|
|
1881
|
-
:return: element-wise exponent of image
|
|
1882
|
-
:rtype: :class:`Image`
|
|
1883
|
-
|
|
1884
|
-
Compute the element-wise power of an Image.
|
|
1885
|
-
|
|
1886
|
-
Example:
|
|
1887
|
-
|
|
1888
|
-
.. runblock:: pycon
|
|
1889
|
-
|
|
1890
|
-
>>> from machinevisiontoolbox import Image
|
|
1891
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
1892
|
-
>>> z = img**3
|
|
1893
|
-
>>> z.array
|
|
1894
|
-
|
|
1895
|
-
..warning:: Values will be wrapped not clipped to the range of the
|
|
1896
|
-
pixel datatype.
|
|
1897
|
-
"""
|
|
1898
|
-
|
|
1899
|
-
#################### ImageCore.py/Image.__add__
|
|
1900
|
-
"""
|
|
1901
|
-
Overloaded ``+`` operator
|
|
1902
|
-
|
|
1903
|
-
:return: element-wise addition of images
|
|
1904
|
-
:rtype: :class:`Image`
|
|
1905
|
-
|
|
1906
|
-
Compute the sum of an Image with another image or a scalar.
|
|
1907
|
-
Supports:
|
|
1908
|
-
|
|
1909
|
-
* image ``+`` image, element-wise
|
|
1910
|
-
* scalar ``+`` image
|
|
1911
|
-
* image ``+`` scalar
|
|
1912
|
-
|
|
1913
|
-
Example:
|
|
1914
|
-
|
|
1915
|
-
.. runblock:: pycon
|
|
1916
|
-
|
|
1917
|
-
>>> from machinevisiontoolbox import Image
|
|
1918
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
1919
|
-
>>> z = img + img
|
|
1920
|
-
>>> z.array
|
|
1921
|
-
>>> z = 10 + img
|
|
1922
|
-
>>> z.array
|
|
1923
|
-
|
|
1924
|
-
..warning:: Values will be wrapped not clipped to the range of the
|
|
1925
|
-
pixel datatype.
|
|
1926
|
-
"""
|
|
1927
|
-
|
|
1928
|
-
#################### ImageCore.py/Image.__iadd__
|
|
1929
|
-
"""
|
|
1930
|
-
Overloaded in-place ``+=`` operator
|
|
1931
|
-
|
|
1932
|
-
:return: self, modified in place
|
|
1933
|
-
:rtype: :class:`Image`
|
|
1934
|
-
|
|
1935
|
-
Add another image or a scalar to an Image in place.
|
|
1936
|
-
|
|
1937
|
-
:seealso: :meth:`__add__`
|
|
1938
|
-
"""
|
|
1939
|
-
|
|
1940
|
-
#################### ImageCore.py/Image.__sub__
|
|
1941
|
-
"""
|
|
1942
|
-
Overloaded ``-`` operator
|
|
1943
|
-
|
|
1944
|
-
:return: element-wise subtraction of images
|
|
1945
|
-
:rtype: :class:`Image`
|
|
1946
|
-
|
|
1947
|
-
Compute the difference of an Image with another image or a scalar.
|
|
1948
|
-
Supports:
|
|
1949
|
-
|
|
1950
|
-
* image ``-`` image, element-wise
|
|
1951
|
-
* scalar ``-`` image
|
|
1952
|
-
* image ``-`` scalar
|
|
1953
|
-
|
|
1954
|
-
Example:
|
|
1955
|
-
|
|
1956
|
-
.. runblock:: pycon
|
|
1957
|
-
|
|
1958
|
-
>>> from machinevisiontoolbox import Image
|
|
1959
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
1960
|
-
>>> z = img - img
|
|
1961
|
-
>>> z.array
|
|
1962
|
-
>>> z = img - 1
|
|
1963
|
-
>>> z.array
|
|
1964
|
-
|
|
1965
|
-
..warning:: Values will be wrapped not clipped to the range of the
|
|
1966
|
-
pixel datatype.
|
|
1967
|
-
"""
|
|
1968
|
-
|
|
1969
|
-
#################### ImageCore.py/Image.__isub__
|
|
1970
|
-
"""
|
|
1971
|
-
Overloaded in-place ``-=`` operator
|
|
1972
|
-
|
|
1973
|
-
:return: self, modified in place
|
|
1974
|
-
:rtype: :class:`Image`
|
|
1975
|
-
|
|
1976
|
-
Subtract another image or a scalar from an Image in place.
|
|
1977
|
-
|
|
1978
|
-
:seealso: :meth:`__sub__`
|
|
1979
|
-
"""
|
|
1980
|
-
|
|
1981
|
-
#################### ImageCore.py/Image.__truediv__
|
|
1982
|
-
"""
|
|
1983
|
-
Overloaded ``/`` operator
|
|
1984
|
-
|
|
1985
|
-
:return: element-wise division of images
|
|
1986
|
-
:rtype: :class:`Image`
|
|
1987
|
-
|
|
1988
|
-
Compute the quotient of an Image with another image or a scalar.
|
|
1989
|
-
Supports:
|
|
1990
|
-
|
|
1991
|
-
* image ``/`` image, element-wise
|
|
1992
|
-
* scalar ``/`` image
|
|
1993
|
-
* image ``/`` scalar
|
|
1994
|
-
|
|
1995
|
-
Example:
|
|
1996
|
-
|
|
1997
|
-
.. runblock:: pycon
|
|
1998
|
-
|
|
1999
|
-
>>> from machinevisiontoolbox import Image
|
|
2000
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2001
|
-
>>> z = img / img
|
|
2002
|
-
>>> z.array
|
|
2003
|
-
>>> z = img / 2
|
|
2004
|
-
>>> z.array
|
|
2005
|
-
|
|
2006
|
-
.. note:: The resulting values are floating point.
|
|
2007
|
-
"""
|
|
2008
|
-
|
|
2009
|
-
#################### ImageCore.py/Image.__itruediv__
|
|
2010
|
-
"""
|
|
2011
|
-
Overloaded in-place ``/=`` operator
|
|
2012
|
-
|
|
2013
|
-
:return: self, modified in place
|
|
2014
|
-
:rtype: :class:`Image`
|
|
2015
|
-
|
|
2016
|
-
Divide an Image in place by another image or a scalar.
|
|
2017
|
-
|
|
2018
|
-
:seealso: :meth:`__truediv__`
|
|
2019
|
-
"""
|
|
2020
|
-
|
|
2021
|
-
#################### ImageCore.py/Image.__floordiv__
|
|
2022
|
-
"""
|
|
2023
|
-
Overloaded ``//`` operator
|
|
2024
|
-
|
|
2025
|
-
:return: element-wise floored division of images
|
|
2026
|
-
:rtype: :class:`Image`
|
|
2027
|
-
|
|
2028
|
-
Compute the integer quotient of an Image with another image or a scalar.
|
|
2029
|
-
Supports:
|
|
2030
|
-
|
|
2031
|
-
* image ``//`` image
|
|
2032
|
-
* scalar ``//`` image
|
|
2033
|
-
* image ``//`` scalar
|
|
2034
|
-
|
|
2035
|
-
Example:
|
|
2036
|
-
|
|
2037
|
-
.. runblock:: pycon
|
|
2038
|
-
|
|
2039
|
-
>>> from machinevisiontoolbox import Image
|
|
2040
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2041
|
-
>>> z = img / 2
|
|
2042
|
-
>>> z.array
|
|
2043
|
-
>>> z = img // 2
|
|
2044
|
-
>>> z.array
|
|
2045
|
-
"""
|
|
2046
|
-
|
|
2047
|
-
#################### ImageCore.py/Image.__ifloordiv__
|
|
2048
|
-
"""
|
|
2049
|
-
Overloaded in-place ``//=`` operator
|
|
2050
|
-
|
|
2051
|
-
:return: self, modified in place
|
|
2052
|
-
:rtype: :class:`Image`
|
|
2053
|
-
|
|
2054
|
-
Divide an Image in place by another image or a scalar, rounding down.
|
|
2055
|
-
|
|
2056
|
-
:seealso: :meth:`__floordiv__`
|
|
2057
|
-
"""
|
|
2058
|
-
|
|
2059
|
-
#################### ImageCore.py/Image.__neg__
|
|
2060
|
-
"""
|
|
2061
|
-
Overloaded unary ``-`` operator
|
|
2062
|
-
|
|
2063
|
-
:return: element-wise negation of image
|
|
2064
|
-
:rtype: :class:`Image`
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
Compute the element-wise negation of an Image.
|
|
2068
|
-
|
|
2069
|
-
Example:
|
|
2070
|
-
|
|
2071
|
-
.. runblock:: pycon
|
|
2072
|
-
|
|
2073
|
-
>>> from machinevisiontoolbox import Image
|
|
2074
|
-
>>> img = Image([[1, -2], [-3, 4]], dtype='int8')
|
|
2075
|
-
>>> img.print()
|
|
2076
|
-
>>> neg_img = -img
|
|
2077
|
-
>>> neg_img.print()
|
|
2078
|
-
"""
|
|
2079
|
-
|
|
2080
|
-
#################### ImageCore.py/Image.__and__
|
|
2081
|
-
"""
|
|
2082
|
-
Overloaded ``&`` operator
|
|
2083
|
-
|
|
2084
|
-
:return: element-wise binary-and of images
|
|
2085
|
-
:rtype: :class:`Image`
|
|
2086
|
-
|
|
2087
|
-
Compute the binary-and of an Image with another image or a scalar.
|
|
2088
|
-
Supports:
|
|
2089
|
-
|
|
2090
|
-
* image ``&`` image
|
|
2091
|
-
* scalar ``&`` image
|
|
2092
|
-
* image ``&`` scalar
|
|
2093
|
-
|
|
2094
|
-
Example:
|
|
2095
|
-
|
|
2096
|
-
.. runblock:: pycon
|
|
2097
|
-
|
|
2098
|
-
>>> from machinevisiontoolbox import Image
|
|
2099
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2100
|
-
>>> z = img & Image([[2, 2], [2, 2]])
|
|
2101
|
-
>>> z.array
|
|
2102
|
-
>>> z = img & 1
|
|
2103
|
-
>>> z.array
|
|
2104
|
-
"""
|
|
2105
|
-
|
|
2106
|
-
#################### ImageCore.py/Image.__iand__
|
|
2107
|
-
"""
|
|
2108
|
-
Overloaded in-place ``&=`` operator
|
|
2109
|
-
|
|
2110
|
-
:return: self, modified in place
|
|
2111
|
-
:rtype: :class:`Image`
|
|
2112
|
-
|
|
2113
|
-
Bitwise-AND an Image in place with another image or a scalar.
|
|
2114
|
-
|
|
2115
|
-
:seealso: :meth:`__and__`
|
|
2116
|
-
"""
|
|
2117
|
-
|
|
2118
|
-
#################### ImageCore.py/Image.__or__
|
|
2119
|
-
"""
|
|
2120
|
-
Overloaded ``|`` operator
|
|
2121
|
-
|
|
2122
|
-
:return: element-wise binary-or of images
|
|
2123
|
-
:rtype: :class:`Image`
|
|
2124
|
-
|
|
2125
|
-
Compute the binary-or of an Image with another image or a scalar.
|
|
2126
|
-
Supports:
|
|
2127
|
-
|
|
2128
|
-
* image ``|`` image
|
|
2129
|
-
* scalar ``|`` image
|
|
2130
|
-
* image ``|`` scalar
|
|
2131
|
-
|
|
2132
|
-
Example:
|
|
2133
|
-
|
|
2134
|
-
.. runblock:: pycon
|
|
2135
|
-
|
|
2136
|
-
>>> from machinevisiontoolbox import Image
|
|
2137
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2138
|
-
>>> z = img | Image([[2, 2], [2, 2]])
|
|
2139
|
-
>>> z.array
|
|
2140
|
-
>>> z = img | 1
|
|
2141
|
-
>>> z.array
|
|
2142
|
-
"""
|
|
2143
|
-
|
|
2144
|
-
#################### ImageCore.py/Image.__ior__
|
|
2145
|
-
"""
|
|
2146
|
-
Overloaded in-place ``|=`` operator
|
|
2147
|
-
|
|
2148
|
-
:return: self, modified in place
|
|
2149
|
-
:rtype: :class:`Image`
|
|
2150
|
-
|
|
2151
|
-
Bitwise-OR an Image in place with another image or a scalar.
|
|
2152
|
-
|
|
2153
|
-
:seealso: :meth:`__or__`
|
|
2154
|
-
"""
|
|
2155
|
-
|
|
2156
|
-
#################### ImageCore.py/Image.__xor__
|
|
2157
|
-
"""
|
|
2158
|
-
Overloaded ``^`` operator
|
|
2159
|
-
|
|
2160
|
-
:return: element-wise binary-xor of images
|
|
2161
|
-
:rtype: :class:`Image`
|
|
2162
|
-
|
|
2163
|
-
Compute the binary-xor of an Image with another image or a scalar.
|
|
2164
|
-
Supports:
|
|
2165
|
-
|
|
2166
|
-
* image ``^`` image
|
|
2167
|
-
* scalar ``^`` image
|
|
2168
|
-
* image ``^`` scalar
|
|
2169
|
-
|
|
2170
|
-
Example:
|
|
2171
|
-
|
|
2172
|
-
.. runblock:: pycon
|
|
2173
|
-
|
|
2174
|
-
>>> from machinevisiontoolbox import Image
|
|
2175
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2176
|
-
>>> z = img ^ Image([[2, 2], [2, 2]])
|
|
2177
|
-
>>> z.array
|
|
2178
|
-
>>> z = img ^ 1
|
|
2179
|
-
>>> z.array
|
|
2180
|
-
"""
|
|
2181
|
-
|
|
2182
|
-
#################### ImageCore.py/Image.__ixor__
|
|
2183
|
-
"""
|
|
2184
|
-
Overloaded in-place ``^=`` operator
|
|
2185
|
-
|
|
2186
|
-
:return: self, modified in place
|
|
2187
|
-
:rtype: :class:`Image`
|
|
2188
|
-
|
|
2189
|
-
Bitwise-XOR an Image in place with another image or a scalar.
|
|
2190
|
-
|
|
2191
|
-
:seealso: :meth:`__xor__`
|
|
2192
|
-
"""
|
|
2193
|
-
|
|
2194
|
-
#################### ImageCore.py/Image.__lshift__
|
|
2195
|
-
"""
|
|
2196
|
-
Overloaded ``<<`` operator
|
|
2197
|
-
|
|
2198
|
-
:return: element-wise binary-left-shift of images
|
|
2199
|
-
:rtype: :class:`Image`
|
|
2200
|
-
|
|
2201
|
-
Left shift pixel values in an Image.
|
|
2202
|
-
|
|
2203
|
-
Example:
|
|
2204
|
-
|
|
2205
|
-
.. runblock:: pycon
|
|
2206
|
-
|
|
2207
|
-
>>> from machinevisiontoolbox import Image
|
|
2208
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2209
|
-
>>> z = img << 1
|
|
2210
|
-
>>> z.array
|
|
2211
|
-
"""
|
|
2212
|
-
|
|
2213
|
-
#################### ImageCore.py/Image.__ilshift__
|
|
2214
|
-
"""
|
|
2215
|
-
Overloaded in-place ``<<=`` operator
|
|
2216
|
-
|
|
2217
|
-
:return: self, modified in place
|
|
2218
|
-
:rtype: :class:`Image`
|
|
2219
|
-
|
|
2220
|
-
Left-shift pixel values of an Image in place.
|
|
2221
|
-
|
|
2222
|
-
:seealso: :meth:`__lshift__`
|
|
2223
|
-
"""
|
|
2224
|
-
|
|
2225
|
-
#################### ImageCore.py/Image.__rshift__
|
|
2226
|
-
"""
|
|
2227
|
-
Overloaded ``>>`` operator
|
|
2228
|
-
|
|
2229
|
-
:return: element-wise binary-right-shift of images
|
|
2230
|
-
:rtype: :class:`Image`
|
|
2231
|
-
|
|
2232
|
-
Right shift pixel values in an Image.
|
|
2233
|
-
|
|
2234
|
-
Example:
|
|
2235
|
-
|
|
2236
|
-
.. runblock:: pycon
|
|
2237
|
-
|
|
2238
|
-
>>> from machinevisiontoolbox import Image
|
|
2239
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2240
|
-
>>> z = img >> 2
|
|
2241
|
-
>>> z.array
|
|
2242
|
-
"""
|
|
2243
|
-
|
|
2244
|
-
#################### ImageCore.py/Image.__irshift__
|
|
2245
|
-
"""
|
|
2246
|
-
Overloaded in-place ``>>=`` operator
|
|
2247
|
-
|
|
2248
|
-
:return: self, modified in place
|
|
2249
|
-
:rtype: :class:`Image`
|
|
2250
|
-
|
|
2251
|
-
Right-shift pixel values of an Image in place.
|
|
2252
|
-
|
|
2253
|
-
:seealso: :meth:`__rshift__`
|
|
2254
|
-
"""
|
|
2255
|
-
|
|
2256
|
-
#################### ImageCore.py/Image.__mod__
|
|
2257
|
-
"""
|
|
2258
|
-
Overloaded ``%`` operator
|
|
2259
|
-
|
|
2260
|
-
:return: image with stacked planes
|
|
2261
|
-
:rtype: :class:`Image`
|
|
2262
|
-
|
|
2263
|
-
``img1 % img2`` results in an image with the planes of ``img1`` followed by the
|
|
2264
|
-
planes of ``img2``. The two images must have the same number of rows and
|
|
2265
|
-
columns and data type. The color order of the resulting image is the color order of ``img1``
|
|
2266
|
-
followed by the color order of ``img2``.
|
|
2267
|
-
|
|
2268
|
-
The operation also supports stacking a scalar as a plane onto an image, in which case the
|
|
2269
|
-
resulting image has one more plane than the original image and the new plane is filled with
|
|
2270
|
-
the scalar value.
|
|
2271
|
-
|
|
2272
|
-
Example:
|
|
2273
|
-
|
|
2274
|
-
.. runblock:: pycon
|
|
2275
|
-
|
|
2276
|
-
>>> from machinevisiontoolbox import Image
|
|
2277
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2278
|
-
>>> z = img % Image([[5, 6], [7, 8]])
|
|
2279
|
-
>>> print(z.nplanes)
|
|
2280
|
-
>>> z = img % 0
|
|
2281
|
-
>>> print(z.nplanes)
|
|
2282
|
-
|
|
2283
|
-
:seealso: :meth:`Pstack`
|
|
2284
|
-
"""
|
|
2285
|
-
|
|
2286
|
-
#################### ImageCore.py/Image.__imod__
|
|
2287
|
-
"""
|
|
2288
|
-
Overloaded in-place ``%=`` operator
|
|
2289
|
-
|
|
2290
|
-
:return: self, modified in place
|
|
2291
|
-
:rtype: :class:`Image`
|
|
2292
|
-
|
|
2293
|
-
Stack the planes of another image (or a scalar plane) onto this Image
|
|
2294
|
-
in place.
|
|
2295
|
-
|
|
2296
|
-
:seealso: :meth:`__mod__`
|
|
2297
|
-
"""
|
|
2298
|
-
|
|
2299
|
-
#################### ImageCore.py/Image.__eq__
|
|
2300
|
-
"""
|
|
2301
|
-
Overloaded ``==`` operator
|
|
2302
|
-
|
|
2303
|
-
:return: element-wise comparison of pixels
|
|
2304
|
-
:rtype: bool :class:`Image`
|
|
2305
|
-
|
|
2306
|
-
Compute the equality between an Image and another image or a scalar.
|
|
2307
|
-
Supports:
|
|
2308
|
-
|
|
2309
|
-
* image ``==`` image
|
|
2310
|
-
* scalar ``==`` image
|
|
2311
|
-
* image ``==`` scalar
|
|
2312
|
-
|
|
2313
|
-
Example:
|
|
2314
|
-
|
|
2315
|
-
.. runblock:: pycon
|
|
2316
|
-
|
|
2317
|
-
>>> from machinevisiontoolbox import Image
|
|
2318
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2319
|
-
>>> (img == 2).print()
|
|
2320
|
-
>>> (img == Image([[0, 2], [3, 4]])).print()
|
|
2321
|
-
|
|
2322
|
-
:seealso: :meth:`true` :meth:`false`
|
|
2323
|
-
"""
|
|
2324
|
-
|
|
2325
|
-
#################### ImageCore.py/Image.sameas
|
|
2326
|
-
"""
|
|
2327
|
-
Compare two images for exact equality and return a scalar bool.
|
|
2328
|
-
|
|
2329
|
-
:param other: image to compare against
|
|
2330
|
-
:type other: :class:`Image`
|
|
2331
|
-
:param colororder: compare ``colororder_str`` values if ``True``, defaults to ``True``
|
|
2332
|
-
:type colororder: bool, optional
|
|
2333
|
-
:return: exact image equality test
|
|
2334
|
-
:rtype: bool
|
|
2335
|
-
|
|
2336
|
-
Unlike ``==``, which returns an element-wise boolean Image,
|
|
2337
|
-
this method returns ``True`` only if:
|
|
2338
|
-
|
|
2339
|
-
* ``other`` is an :class:`Image`
|
|
2340
|
-
* image shape is identical
|
|
2341
|
-
* image dtype is identical
|
|
2342
|
-
* color order is identical (if ``colororder`` is ``True``)
|
|
2343
|
-
* all pixel values are identical
|
|
2344
|
-
|
|
2345
|
-
Example:
|
|
2346
|
-
|
|
2347
|
-
.. runblock:: pycon
|
|
2348
|
-
|
|
2349
|
-
>>> from machinevisiontoolbox import Image
|
|
2350
|
-
>>> a = Image([[1, 2], [3, 4]])
|
|
2351
|
-
>>> b = Image([[1, 2], [3, 4]])
|
|
2352
|
-
>>> a.sameas(b)
|
|
2353
|
-
True
|
|
2354
|
-
"""
|
|
2355
|
-
|
|
2356
|
-
#################### ImageCore.py/Image.__ne__
|
|
2357
|
-
"""
|
|
2358
|
-
Overloaded ``!=`` operator
|
|
2359
|
-
|
|
2360
|
-
:return: element-wise comparison of pixels
|
|
2361
|
-
:rtype: bool :class:`Image`
|
|
2362
|
-
|
|
2363
|
-
Compute the inequality between an Image and another image or a scalar.
|
|
2364
|
-
Supports:
|
|
2365
|
-
|
|
2366
|
-
* image ``!=`` image
|
|
2367
|
-
* scalar ``!=`` image
|
|
2368
|
-
* image ``!=`` scalar
|
|
2369
|
-
|
|
2370
|
-
Example:
|
|
2371
|
-
|
|
2372
|
-
.. runblock:: pycon
|
|
2373
|
-
|
|
2374
|
-
>>> from machinevisiontoolbox import Image
|
|
2375
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2376
|
-
>>> (img != 2).print()
|
|
2377
|
-
>>> (img != Image([[0, 2], [3, 4]])).print()
|
|
2378
|
-
|
|
2379
|
-
:seealso: :meth:`true` :meth:`false`
|
|
2380
|
-
"""
|
|
2381
|
-
|
|
2382
|
-
#################### ImageCore.py/Image.__gt__
|
|
2383
|
-
"""
|
|
2384
|
-
Overloaded ``>`` operator
|
|
2385
|
-
|
|
2386
|
-
:return: element-wise comparison of pixels
|
|
2387
|
-
:rtype: bool :class:`Image`
|
|
2388
|
-
|
|
2389
|
-
Compute the inequality between an Image and another image or a scalar.
|
|
2390
|
-
Supports:
|
|
2391
|
-
|
|
2392
|
-
* image ``>`` image
|
|
2393
|
-
* scalar ``>`` image
|
|
2394
|
-
* image ``>`` scalar
|
|
2395
|
-
|
|
2396
|
-
Example:
|
|
2397
|
-
|
|
2398
|
-
.. runblock:: pycon
|
|
2399
|
-
|
|
2400
|
-
>>> from machinevisiontoolbox import Image
|
|
2401
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2402
|
-
>>> (img > 2).print()
|
|
2403
|
-
>>> (img > Image([[0, 2], [3, 4]])).print()
|
|
2404
|
-
|
|
2405
|
-
:seealso: :meth:`true` :meth:`false`
|
|
2406
|
-
"""
|
|
2407
|
-
|
|
2408
|
-
#################### ImageCore.py/Image.__ge__
|
|
2409
|
-
"""
|
|
2410
|
-
Overloaded ``>=`` operator
|
|
2411
|
-
|
|
2412
|
-
:return: element-wise comparison of pixels
|
|
2413
|
-
:rtype: bool :class:`Image`
|
|
2414
|
-
|
|
2415
|
-
Compute the inequality between an Image and another image or a scalar.
|
|
2416
|
-
Supports:
|
|
2417
|
-
|
|
2418
|
-
* image ``>=`` image
|
|
2419
|
-
* scalar ``>=`` image
|
|
2420
|
-
* image ``>=`` scalar
|
|
2421
|
-
|
|
2422
|
-
Example:
|
|
2423
|
-
|
|
2424
|
-
.. runblock:: pycon
|
|
2425
|
-
|
|
2426
|
-
>>> from machinevisiontoolbox import Image
|
|
2427
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2428
|
-
>>> (img >= 2).print()
|
|
2429
|
-
>>> (img >= Image([[0, 2], [3, 4]])).print()
|
|
2430
|
-
|
|
2431
|
-
:seealso: :meth:`true` :meth:`false`
|
|
2432
|
-
"""
|
|
2433
|
-
|
|
2434
|
-
#################### ImageCore.py/Image.__lt__
|
|
2435
|
-
"""
|
|
2436
|
-
Overloaded ``<`` operator
|
|
2437
|
-
|
|
2438
|
-
:return: element-wise comparison of images
|
|
2439
|
-
:rtype: bool :class:`Image`
|
|
2440
|
-
|
|
2441
|
-
Compute the inequality between an Image and another image or a scalar.
|
|
2442
|
-
Supports:
|
|
2443
|
-
|
|
2444
|
-
* image ``<`` image
|
|
2445
|
-
* scalar ``<`` image
|
|
2446
|
-
* image ``<`` scalar
|
|
2447
|
-
|
|
2448
|
-
Example:
|
|
2449
|
-
|
|
2450
|
-
.. runblock:: pycon
|
|
2451
|
-
|
|
2452
|
-
>>> from machinevisiontoolbox import Image
|
|
2453
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2454
|
-
>>> (img < 2).print()
|
|
2455
|
-
>>> (img < Image([[0, 2], [3, 4]])).print()
|
|
2456
|
-
|
|
2457
|
-
:seealso: :meth:`true` :meth:`false`
|
|
2458
|
-
"""
|
|
2459
|
-
|
|
2460
|
-
#################### ImageCore.py/Image.__le__
|
|
2461
|
-
"""
|
|
2462
|
-
Overloaded ``<=`` operator
|
|
2463
|
-
|
|
2464
|
-
:return: element-wise comparison of images
|
|
2465
|
-
:rtype: bool :class:`Image`
|
|
2466
|
-
|
|
2467
|
-
Compute the inequality between an Image and another image or a scalar.
|
|
2468
|
-
Supports:
|
|
2469
|
-
|
|
2470
|
-
* image ``<=`` image
|
|
2471
|
-
* scalar ``<=`` image
|
|
2472
|
-
* image ``<=`` scalar
|
|
2473
|
-
|
|
2474
|
-
Example:
|
|
2475
|
-
|
|
2476
|
-
.. runblock:: pycon
|
|
2477
|
-
|
|
2478
|
-
>>> from machinevisiontoolbox import Image
|
|
2479
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2480
|
-
>>> (img <= 2).print()
|
|
2481
|
-
>>> (img <= Image([[0, 2], [3, 4]])).print()
|
|
2482
|
-
|
|
2483
|
-
:seealso: :meth:`true` :meth:`false`
|
|
2484
|
-
"""
|
|
2485
|
-
|
|
2486
|
-
#################### ImageCore.py/Image.__invert__
|
|
2487
|
-
"""
|
|
2488
|
-
Overloaded ``~`` operator
|
|
2489
|
-
|
|
2490
|
-
:return: element-wise inversion of logical values
|
|
2491
|
-
:rtype: boo, :class:`Image`
|
|
2492
|
-
|
|
2493
|
-
Returns logical not operation where image values are interpretted as:
|
|
2494
|
-
|
|
2495
|
-
* floating image: True is 1.0, False is 0.0
|
|
2496
|
-
* integer image: True is maximum value, False is 0 True is 1 and False is 0.
|
|
2497
|
-
|
|
2498
|
-
Example:
|
|
2499
|
-
|
|
2500
|
-
.. runblock:: pycon
|
|
2501
|
-
|
|
2502
|
-
>>> from machinevisiontoolbox import Image
|
|
2503
|
-
>>> img = Image([[True, False], [False, True]])
|
|
2504
|
-
>>> z = ~img
|
|
2505
|
-
>>> z.print()
|
|
2506
|
-
"""
|
|
2507
|
-
|
|
2508
|
-
#################### ImageCore.py/Image.abs
|
|
2509
|
-
"""
|
|
2510
|
-
Absolute value of image
|
|
2511
|
-
|
|
2512
|
-
:return: element-wise absolute value of image
|
|
2513
|
-
:rtype: :class:`Image`
|
|
2514
|
-
|
|
2515
|
-
Return element-wise absolute value of pixel values.
|
|
2516
|
-
|
|
2517
|
-
Example:
|
|
2518
|
-
|
|
2519
|
-
.. runblock:: pycon
|
|
2520
|
-
|
|
2521
|
-
>>> from machinevisiontoolbox import Image
|
|
2522
|
-
>>> img = Image([[-1, 2], [3, -4]], dtype='int8')
|
|
2523
|
-
>>> img.abs().print()
|
|
2524
|
-
"""
|
|
2525
|
-
|
|
2526
|
-
#################### ImageCore.py/Image.sqrt
|
|
2527
|
-
"""
|
|
2528
|
-
Square root of image
|
|
2529
|
-
|
|
2530
|
-
:return: element-wise square root of image
|
|
2531
|
-
:rtype: :class:`Image`
|
|
2532
|
-
|
|
2533
|
-
Return element-wise square root of pixel values.
|
|
2534
|
-
|
|
2535
|
-
Example:
|
|
2536
|
-
|
|
2537
|
-
.. runblock:: pycon
|
|
2538
|
-
|
|
2539
|
-
>>> from machinevisiontoolbox import Image
|
|
2540
|
-
>>> img = Image([[1, 2], [3, 4]])
|
|
2541
|
-
>>> img.sqrt().print()
|
|
2542
|
-
"""
|
|
2543
|
-
|
|
2544
|
-
#################### ImageCore.py/Image.draw_line
|
|
2545
|
-
"""
|
|
2546
|
-
Draw line into image
|
|
2547
|
-
|
|
2548
|
-
:param start: start coordinate (u,v)
|
|
2549
|
-
:type start: array_like(2)
|
|
2550
|
-
:param end: end coordinate (u,v)
|
|
2551
|
-
:type end: array_like(2)
|
|
2552
|
-
:param kwargs: parameters passed to :func:`~machinevisiontoolbox.base.graphics.draw_line`
|
|
2553
|
-
|
|
2554
|
-
Example, "burn" a line into the Mona Lisa image:
|
|
2555
|
-
|
|
2556
|
-
.. code-block:: python
|
|
2557
|
-
|
|
2558
|
-
from machinevisiontoolbox import Image
|
|
2559
|
-
img = Image.Read("monalisa.png")
|
|
2560
|
-
img.draw_line((20,30), (500,600), thickness=5, color="orange")
|
|
2561
|
-
img.disp()
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
.. plot::
|
|
2565
|
-
|
|
2566
|
-
from machinevisiontoolbox import Image
|
|
2567
|
-
img = Image.Read("monalisa.png")
|
|
2568
|
-
img.draw_line((20,30), (500,600), thickness=5, color="orange")
|
|
2569
|
-
img.disp()
|
|
2570
|
-
|
|
2571
|
-
.. note:: If ``image`` has multiple planes then ``color`` should have the same number
|
|
2572
|
-
of elements as the image has planes. If it is a scalar that value is used
|
|
2573
|
-
for each color plane. For a color image ``color`` can be
|
|
2574
|
-
a string color name.
|
|
2575
|
-
|
|
2576
|
-
:seealso: :func:`~machinevisiontoolbox.base.graphics.draw_line`
|
|
2577
|
-
"""
|
|
2578
|
-
|
|
2579
|
-
#################### ImageCore.py/Image.draw_circle
|
|
2580
|
-
"""
|
|
2581
|
-
Draw circle into image
|
|
2582
|
-
|
|
2583
|
-
:param centre: centre coordinate (u,v)
|
|
2584
|
-
:type centre: array_like(2)
|
|
2585
|
-
:param radius: circle radius in pixels
|
|
2586
|
-
:type radius: int
|
|
2587
|
-
:param kwargs: parameters passed to :func:`~machinevisiontoolbox.base.graphics.draw_circle`
|
|
2588
|
-
|
|
2589
|
-
Example, "burn" some circles (confetti) into the Mona Lisa:
|
|
2590
|
-
|
|
2591
|
-
.. code-block:: pycon
|
|
2592
|
-
|
|
2593
|
-
>>> from machinevisiontoolbox import Image
|
|
2594
|
-
>>> import matplotlib as mpl
|
|
2595
|
-
>>> img = Image.Read("monalisa.png")
|
|
2596
|
-
>>> colors = mpl.color_sequences["petroff10"]
|
|
2597
|
-
>>> for color in colors:
|
|
2598
|
-
... u = np.random.randint(20, img.umax-20)
|
|
2599
|
-
v = np.random.randint(20, img.vmax-20)
|
|
2600
|
-
r = np.random.randint(10, 50)
|
|
2601
|
-
img.draw_circle((u, v), r, thickness=-1, color=[255*c for c in color])
|
|
2602
|
-
>>> img.disp(img)
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
.. plot::
|
|
2606
|
-
|
|
2607
|
-
from machinevisiontoolbox import Image
|
|
2608
|
-
import matplotlib as mpl
|
|
2609
|
-
img = Image.Read("monalisa.png")
|
|
2610
|
-
for color in mpl.color_sequences["petroff10"]:
|
|
2611
|
-
u = np.random.randint(20, img.umax-20)
|
|
2612
|
-
v = np.random.randint(20, img.vmax-20)
|
|
2613
|
-
r = np.random.randint(10, 50)
|
|
2614
|
-
img.draw_circle((u, v), r, thickness=-1, color=[255*c for c in color])
|
|
2615
|
-
img.disp(img)
|
|
2616
|
-
|
|
2617
|
-
.. note:: If ``image`` has multiple planes then ``color`` should have the same number
|
|
2618
|
-
of elements as the image has planes. If it is a scalar that value is used
|
|
2619
|
-
for each color plane. For a color image ``color`` can be
|
|
2620
|
-
a string color name.
|
|
2621
|
-
|
|
2622
|
-
:seealso: :func:`~machinevisiontoolbox.base.graphics.draw_circle`
|
|
2623
|
-
"""
|
|
2624
|
-
|
|
2625
|
-
#################### ImageCore.py/Image.draw_box
|
|
2626
|
-
"""
|
|
2627
|
-
Draw box into image
|
|
2628
|
-
|
|
2629
|
-
:param kwargs: parameters passed to :func:`~machinevisiontoolbox.base.graphics.draw_box`
|
|
2630
|
-
|
|
2631
|
-
There are myriad ways to specify the corners of the box.
|
|
2632
|
-
|
|
2633
|
-
Example, draw boxes over the eyes of the Mona Lisa:
|
|
2634
|
-
|
|
2635
|
-
.. code-block:: python
|
|
2636
|
-
|
|
2637
|
-
from machinevisiontoolbox import Image
|
|
2638
|
-
img = Image.Read("monalisa.png")
|
|
2639
|
-
img.draw_box(lb=(245,170), rt=(290, 210), color="yellow", thickness=5)
|
|
2640
|
-
img.draw_box(lb=(315, 175), rt=(370,205), color="blue", thickness=-1)
|
|
2641
|
-
img.disp()
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
.. plot::
|
|
2645
|
-
|
|
2646
|
-
from machinevisiontoolbox import Image
|
|
2647
|
-
img = Image.Read("monalisa.png")
|
|
2648
|
-
img.draw_box(lt=(245,210), rb=(290, 170), color="yellow", thickness=5)
|
|
2649
|
-
img.draw_box(lt=(315, 205), rb=(370,175), color="blue", thickness=-1)
|
|
2650
|
-
img.disp()
|
|
2651
|
-
|
|
2652
|
-
.. note:: If ``image`` has multiple planes then ``color`` should have the same number
|
|
2653
|
-
of elements as the image has planes. If it is a scalar that value is used
|
|
2654
|
-
for each color plane. For a color image ``color`` can be
|
|
2655
|
-
a string color name.
|
|
2656
|
-
|
|
2657
|
-
:seealso: :func:`~machinevisiontoolbox.base.graphics.draw_box`
|
|
2658
|
-
"""
|
|
2659
|
-
|
|
2660
|
-
#################### ImageCore.py/Image.draw_labelbox
|
|
2661
|
-
"""
|
|
2662
|
-
Draw label box into image
|
|
2663
|
-
|
|
2664
|
-
:param text: text for the box label
|
|
2665
|
-
:type text: str
|
|
2666
|
-
:param kwargs: parameters passed to :func:`~machinevisiontoolbox.base.graphics.draw_labelbox` to
|
|
2667
|
-
specify the box position, color, etc.
|
|
2668
|
-
|
|
2669
|
-
The box position is specified by the parameters accepted by :func:`~machinevisiontoolbox.base.graphics.draw_box`
|
|
2670
|
-
|
|
2671
|
-
Example:
|
|
2672
|
-
|
|
2673
|
-
.. code-block:: python
|
|
2674
|
-
|
|
2675
|
-
from machinevisiontoolbox import Image
|
|
2676
|
-
img = Image.Read("monalisa.png")
|
|
2677
|
-
img.draw_labelbox("Face", lb=(243,111), rt=(394,329), color="yellow", fontheight=20)
|
|
2678
|
-
img.disp()
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
.. plot::
|
|
2682
|
-
|
|
2683
|
-
from machinevisiontoolbox import Image
|
|
2684
|
-
img = Image.Read("monalisa.png")
|
|
2685
|
-
img.draw_labelbox("Face", lb=(243,111), rt=(394,329), color="yellow", fontheight=20)
|
|
2686
|
-
img.disp()
|
|
2687
|
-
|
|
2688
|
-
.. note:: If ``image`` has multiple planes then ``color`` should have the same number
|
|
2689
|
-
of elements as the image has planes. If it is a scalar that value is used
|
|
2690
|
-
for each color plane. For a color image ``color`` can be
|
|
2691
|
-
a string color name.
|
|
2692
|
-
|
|
2693
|
-
:seealso: :func:`~machinevisiontoolbox.base.graphics.draw_labelbox`
|
|
2694
|
-
"""
|
|
2695
|
-
|
|
2696
|
-
#################### ImageCore.py/Image.draw_text
|
|
2697
|
-
"""
|
|
2698
|
-
Draw text into image
|
|
2699
|
-
:param pos: text position (u,v)
|
|
2700
|
-
:type pos: array_like(2)
|
|
2701
|
-
:param text: text to draw
|
|
2702
|
-
:type text: str
|
|
2703
|
-
:param kwargs: parameters passed to :func:`~machinevisiontoolbox.base.graphics.draw_text`
|
|
2704
|
-
|
|
2705
|
-
Example:
|
|
2706
|
-
|
|
2707
|
-
.. code-block:: python
|
|
2708
|
-
|
|
2709
|
-
from machinevisiontoolbox import Image
|
|
2710
|
-
img = Image.Read("monalisa.png")
|
|
2711
|
-
img.draw_text((340,290), "Smile!", fontheight=40, color="yellow")
|
|
2712
|
-
img.disp()
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
.. plot::
|
|
2716
|
-
|
|
2717
|
-
from machinevisiontoolbox import Image
|
|
2718
|
-
img = Image.Read("monalisa.png")
|
|
2719
|
-
img.draw_text((340,290), "Smile!", fontheight=40, color="yellow")
|
|
2720
|
-
img.disp()
|
|
2721
|
-
|
|
2722
|
-
.. note:: If ``image`` has multiple planes then ``color`` should have the same number
|
|
2723
|
-
of elements as the image has planes. If it is a scalar that value is used
|
|
2724
|
-
for each color plane. For a color image ``color`` can be
|
|
2725
|
-
a string color name.
|
|
2726
|
-
|
|
2727
|
-
:seealso: :func:`~machinevisiontoolbox.base.graphics.draw_text`
|
|
2728
|
-
"""
|
|
2729
|
-
|
|
2730
|
-
#################### ImageCore.py/Image.draw_point
|
|
2731
|
-
"""
|
|
2732
|
-
Draw a marker in image
|
|
2733
|
-
|
|
2734
|
-
:param pos: position of marker
|
|
2735
|
-
:type pos: array_like(2), ndarray(2,n), list of 2-tuples
|
|
2736
|
-
:param marker: marker character, defaults to "+"
|
|
2737
|
-
:type marker: str, optional
|
|
2738
|
-
:param text: text label, defaults to None
|
|
2739
|
-
:type text: str, optional
|
|
2740
|
-
:param kwargs: parameters passed to :func:`~machinevisiontoolbox.base.graphics.draw_point`
|
|
2741
|
-
|
|
2742
|
-
Example:
|
|
2743
|
-
|
|
2744
|
-
.. runblock:: pycon
|
|
2745
|
-
|
|
2746
|
-
>>> from machinevisiontoolbox import Image
|
|
2747
|
-
>>> img = Image.Read("monalisa.png")
|
|
2748
|
-
>>> img.draw_point((270,194), "+", "eye", fontsize=1, color="yellow")
|
|
2749
|
-
>>> img.draw_point((293,246), "*", "nose", fontsize=1, color="blue")
|
|
2750
|
-
>>> img.disp()
|
|
2751
|
-
|
|
2752
|
-
.. plot::
|
|
2753
|
-
|
|
2754
|
-
from machinevisiontoolbox import Image
|
|
2755
|
-
img = Image.Read("monalisa.png")
|
|
2756
|
-
img.draw_point((270,194), "+", "eye", fontsize=1, color="yellow")
|
|
2757
|
-
img.draw_point((293,246), "*", "nose", fontsize=1, color="blue")
|
|
2758
|
-
img.disp()
|
|
2759
|
-
|
|
2760
|
-
.. note:: If ``image`` has multiple planes then ``color`` should have the same number
|
|
2761
|
-
of elements as the image has planes. If it is a scalar that value is used
|
|
2762
|
-
for each color plane. For a color image ``color`` can be
|
|
2763
|
-
a string color name.
|
|
2764
|
-
|
|
2765
|
-
:seealso: :func:`~machinevisiontoolbox.base.graphics.draw_text`
|
|
2766
|
-
"""
|
|
2767
|
-
|
|
2768
|
-
#################### ImageCore.py/Image.Pstack
|
|
2769
|
-
"""
|
|
2770
|
-
Concatenation of image planes
|
|
2771
|
-
|
|
2772
|
-
:param images: images to concatenate plane-wise
|
|
2773
|
-
:type images: iterable of :class:`Image`
|
|
2774
|
-
:param colororder: color order for the result, defaults to None
|
|
2775
|
-
:type colororder: str, optional
|
|
2776
|
-
:raises ValueError: all images must have the same dtype
|
|
2777
|
-
:raises ValueError: all images must have the same size
|
|
2778
|
-
:return: plane-stacked image
|
|
2779
|
-
:rtype: :class:`Image`
|
|
2780
|
-
|
|
2781
|
-
Create a new image by stacking the planes of the input images.
|
|
2782
|
-
All images must have the same width, height and dtype. The resulting
|
|
2783
|
-
image has a number of planes equal to the sum of planes in all input images.
|
|
2784
|
-
|
|
2785
|
-
If ``colororder`` is not specified and all images have color orders defined,
|
|
2786
|
-
the result's color order is constructed by concatenating the color orders
|
|
2787
|
-
of the input images.
|
|
2788
|
-
|
|
2789
|
-
Example:
|
|
2790
|
-
|
|
2791
|
-
.. runblock:: pycon
|
|
2792
|
-
|
|
2793
|
-
>>> from machinevisiontoolbox import Image
|
|
2794
|
-
>>> r = Image.Random(size=(100, 120), colororder='R')
|
|
2795
|
-
>>> g = Image.Random(size=(100, 120), colororder='G')
|
|
2796
|
-
>>> b = Image.Random(size=(100, 120), colororder='B')
|
|
2797
|
-
>>> rgb = Image.Pstack((r, g, b))
|
|
2798
|
-
>>> rgb.nplanes
|
|
2799
|
-
>>> rgb.colororder_str
|
|
2800
|
-
|
|
2801
|
-
:seealso: :meth:`Vstack` :meth:`Hstack`
|
|
2802
|
-
|
|
2803
|
-
AUTO_EDIT
|
|
2804
|
-
"""
|
|
2805
|
-
|
|
2806
|
-
#################### ImageCore.py/Image.fliplr
|
|
2807
|
-
"""
|
|
2808
|
-
Flip image left-right
|
|
2809
|
-
|
|
2810
|
-
:return: horizontally flipped image
|
|
2811
|
-
:rtype: :class:`Image`
|
|
2812
|
-
|
|
2813
|
-
Example:
|
|
2814
|
-
|
|
2815
|
-
.. runblock:: pycon
|
|
2816
|
-
|
|
2817
|
-
>>> from machinevisiontoolbox import Image
|
|
2818
|
-
>>> img = Image([[1, 2, 3], [4, 5, 6]])
|
|
2819
|
-
>>> img.fliplr().A
|
|
2820
|
-
|
|
2821
|
-
:seealso: :meth:`flipud`
|
|
2822
|
-
"""
|
|
2823
|
-
|
|
2824
|
-
#################### ImageCore.py/Image.flipud
|
|
2825
|
-
"""
|
|
2826
|
-
Flip image up-down
|
|
2827
|
-
|
|
2828
|
-
:return: vertically flipped image
|
|
2829
|
-
:rtype: :class:`Image`
|
|
2830
|
-
|
|
2831
|
-
Example:
|
|
2832
|
-
|
|
2833
|
-
.. runblock:: pycon
|
|
2834
|
-
|
|
2835
|
-
>>> from machinevisiontoolbox import Image
|
|
2836
|
-
>>> img = Image([[1, 2, 3], [4, 5, 6]])
|
|
2837
|
-
>>> img.flipud().A
|
|
2838
|
-
|
|
2839
|
-
:seealso: :meth:`fliplr`
|
|
2840
|
-
"""
|
|
2841
|
-
|
|
2842
|
-
#################### ImageCore.py/Image.fixbad
|
|
2843
|
-
"""
|
|
2844
|
-
Fix bad values in image
|
|
2845
|
-
|
|
2846
|
-
:param nan: value to replace NaN values, defaults to 0.0
|
|
2847
|
-
:type nan: scalar or array-like(n), optional
|
|
2848
|
-
:param posinf: value to replace positive infinity values, defaults to maximum value of image dtype
|
|
2849
|
-
:type posinf: scalar or array-like(n), optional
|
|
2850
|
-
:param neginf: value to replace negative infinity values, defaults to negative maximum value of image dtype
|
|
2851
|
-
:type neginf: scalar or array-like(n), optional
|
|
2852
|
-
:return: image with bad values fixed
|
|
2853
|
-
:rtype: :class:`~machinevisiontoolbox.ImageCore.Image` instance
|
|
2854
|
-
|
|
2855
|
-
Return an image where any pixel that contains a NaN or Inf values has been
|
|
2856
|
-
replaced by the specified replacement values.
|
|
2857
|
-
|
|
2858
|
-
The replacement value can be a scalar, in which case all bad values are replaced
|
|
2859
|
-
by the same value, or an array-like of length n, where n is the number of
|
|
2860
|
-
channels in the image, in which case each channel is replaced by the
|
|
2861
|
-
corresponding value.
|
|
2862
|
-
|
|
2863
|
-
By default NaN values are replaced by 0, positive infinity values are replaced
|
|
2864
|
-
by the maximum value of the image dtype, and negative infinity values are
|
|
2865
|
-
replaced by the negative maximum value of the image dtype.
|
|
2866
|
-
|
|
2867
|
-
Example:
|
|
2868
|
-
|
|
2869
|
-
.. runblock:: pycon
|
|
2870
|
-
|
|
2871
|
-
>>> from machinevisiontoolbox import Image
|
|
2872
|
-
>>> from numpy import nan, inf
|
|
2873
|
-
>>> img = Image([[1, 2, 3], [4, nan, 6], [7, 8, inf]])
|
|
2874
|
-
>>> img.fixbad(posinf=99).print()
|
|
2875
|
-
|
|
2876
|
-
"""
|
|
2877
|
-
|