machinevision-toolbox-python 0.9.4__py3-none-any.whl → 0.9.7__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.
Files changed (45) hide show
  1. {machinevision_toolbox_python-0.9.4.dist-info → machinevision_toolbox_python-0.9.7.dist-info}/METADATA +18 -15
  2. machinevision_toolbox_python-0.9.7.dist-info/RECORD +42 -0
  3. {machinevision_toolbox_python-0.9.4.dist-info → machinevision_toolbox_python-0.9.7.dist-info}/WHEEL +1 -1
  4. machinevisiontoolbox/BagOfWords.py +51 -48
  5. machinevisiontoolbox/BundleAdjust.py +193 -172
  6. machinevisiontoolbox/Camera.py +551 -454
  7. machinevisiontoolbox/ImageBlobs.py +151 -119
  8. machinevisiontoolbox/ImageColor.py +93 -87
  9. machinevisiontoolbox/ImageConstants.py +34 -27
  10. machinevisiontoolbox/ImageCore.py +171 -138
  11. machinevisiontoolbox/ImageIO.py +135 -73
  12. machinevisiontoolbox/ImageLineFeatures.py +50 -42
  13. machinevisiontoolbox/ImageMorph.py +101 -94
  14. machinevisiontoolbox/ImageMultiview.py +52 -49
  15. machinevisiontoolbox/ImagePointFeatures.py +331 -209
  16. machinevisiontoolbox/ImageProcessing.py +119 -111
  17. machinevisiontoolbox/ImageRegionFeatures.py +90 -84
  18. machinevisiontoolbox/ImageReshape.py +165 -112
  19. machinevisiontoolbox/ImageSpatial.py +181 -170
  20. machinevisiontoolbox/ImageWholeFeatures.py +77 -66
  21. machinevisiontoolbox/PointCloud.py +43 -34
  22. machinevisiontoolbox/Sources.py +106 -76
  23. machinevisiontoolbox/VisualServo.py +326 -267
  24. machinevisiontoolbox/__init__.py +22 -5
  25. machinevisiontoolbox/base/__init__.py +49 -56
  26. machinevisiontoolbox/base/color.py +246 -200
  27. machinevisiontoolbox/base/data.py +17 -13
  28. machinevisiontoolbox/base/esttheta.py +13 -9
  29. machinevisiontoolbox/base/findpeaks.py +40 -36
  30. machinevisiontoolbox/base/graphics.py +123 -68
  31. machinevisiontoolbox/base/imageio.py +235 -200
  32. machinevisiontoolbox/base/meshgrid.py +4 -2
  33. machinevisiontoolbox/base/shapes.py +59 -51
  34. machinevisiontoolbox/base/types.py +19 -10
  35. machinevisiontoolbox/blocks/__init__.py +1 -1
  36. machinevisiontoolbox/blocks/camera.py +62 -54
  37. machinevisiontoolbox/blocks/{aside_test_blocks.py → test_blocks.py} +3 -5
  38. machinevisiontoolbox/fiducial.py +20 -24
  39. machinevisiontoolbox/newcameras.py +11 -6
  40. machinevision_toolbox_python-0.9.4.data/data/RELEASE +0 -1
  41. machinevision_toolbox_python-0.9.4.dist-info/RECORD +0 -45
  42. machinevisiontoolbox/base/io.py +0 -954
  43. machinevisiontoolbox/blocks/tex2icon.py +0 -108
  44. {machinevision_toolbox_python-0.9.4.dist-info → machinevision_toolbox_python-0.9.7.dist-info}/LICENSE +0 -0
  45. {machinevision_toolbox_python-0.9.4.dist-info → machinevision_toolbox_python-0.9.7.dist-info}/top_level.txt +0 -0
@@ -1,29 +1,31 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: machinevision-toolbox-python
3
- Version: 0.9.4
4
- Summary: A machine vision for education and research
5
- Home-page: https://github.com/petercorke/machinevision-toolbox-python
6
- Author: Peter Corke and Dorian Tsai
7
- License: MIT
3
+ Version: 0.9.7
4
+ Summary: Python tools for machine vision - education and research
5
+ Author: Dorian Tsai
6
+ Author-email: Peter Corke <rvc@petercorke.com>
7
+ Project-URL: Homepage, https://github.com/petercorke/machinevision-toolbox-python
8
+ Project-URL: Bug Tracker, https://github.com/pypa/sampleproject/issues
8
9
  Project-URL: Documentation, https://petercorke.github.io/machinevision-toolbox-python
9
10
  Project-URL: Source, https://github.com/petercorke/machinevision-toolbox-python
10
- Project-URL: Tracker, https://github.com/petercorke/machinevision-toolbox-python/issues
11
- Project-URL: Coverage, https://codecov.io/gh/petercorke/machinevision-toolbox-python
12
- Keywords: python machine-vision computer-vision multiview-geometry features color blobs
11
+ Keywords: machine vision,computer vision,multiview geometry,stereo vision,bundle adjustment,visual servoing,image features,color,blobs,morphology,image segmentation,opencv,open3d
13
12
  Classifier: Development Status :: 5 - Production/Stable
14
13
  Classifier: Intended Audience :: Developers
15
- Classifier: License :: OSI Approved :: MIT License
16
14
  Classifier: Programming Language :: Python :: 3.7
17
15
  Classifier: Programming Language :: Python :: 3.8
18
16
  Classifier: Programming Language :: Python :: 3.9
19
17
  Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
20
21
  Requires-Python: >=3.7
21
22
  Description-Content-Type: text/markdown
22
23
  License-File: LICENSE
23
- Requires-Dist: numpy
24
+ Requires-Dist: numpy >=1.17.4
24
25
  Requires-Dist: scipy
25
26
  Requires-Dist: matplotlib
26
27
  Requires-Dist: opencv-python
28
+ Requires-Dist: open3d
27
29
  Requires-Dist: opencv-contrib-python
28
30
  Requires-Dist: spatialmath-python
29
31
  Requires-Dist: pgraph-python
@@ -31,13 +33,16 @@ Requires-Dist: ansitable
31
33
  Requires-Dist: mvtb-data
32
34
  Provides-Extra: dev
33
35
  Requires-Dist: pytest ; extra == 'dev'
34
- Requires-Dist: pytest-cov ; extra == 'dev'
36
+ Requires-Dist: coverage ; extra == 'dev'
35
37
  Requires-Dist: flake8 ; extra == 'dev'
36
- Requires-Dist: pyyaml ; extra == 'dev'
37
38
  Provides-Extra: docs
38
39
  Requires-Dist: sphinx ; extra == 'docs'
40
+ Requires-Dist: recommonmark ; extra == 'docs'
39
41
  Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
40
42
  Requires-Dist: sphinx-autorun ; extra == 'docs'
43
+ Requires-Dist: sphinxcontrib-jsmath ; extra == 'docs'
44
+ Requires-Dist: sphinx-markdown-tables ; extra == 'docs'
45
+ Requires-Dist: sphinx-favicon ; extra == 'docs'
41
46
 
42
47
  # Machine Vision Toolbox for Python
43
48
 
@@ -51,9 +56,8 @@ Requires-Dist: sphinx-autorun ; extra == 'docs'
51
56
  [![Powered by Open3D](https://raw.githubusercontent.com/petercorke/machinevision-toolbox-python/master/.github/svg/open3d_powered.svg)](https://open3d.org)
52
57
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
53
58
 
54
- [![Build Status](https://github.com/petercorke/spatialmath-python/workflows/build/badge.svg?branch=master)](https://github.com/petercorke/machinevisiontoolbox-python/actions?query=workflow%3Abuild)
59
+ [![Build Status](https://github.com/petercorke/machinevision-toolbox-python/workflows/Test-master/badge.svg?branch=master)](https://github.com/petercorke/machinevision-toolbox-python/actions?query=workflow%3Abuild)
55
60
  [![Coverage](https://codecov.io/gh/petercorke/machinevision-toolbox-python/branch/master/graph/badge.svg)](https://codecov.io/gh/petercorke/machinevision-toolbox-python)
56
- [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/petercorke/machinevision-toolbox-python.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/petercorke/machinevision-toolbox-python/context:python)
57
61
  [![PyPI - Downloads](https://img.shields.io/pypi/dw/machinevision-toolbox-python)](https://pypistats.org/packages/machinevision-toolbox-python)
58
62
 
59
63
  <!-- [![GitHub stars](https://img.shields.io/github/stars/petercorke/machinevision-toolbox-python.svg?style=social&label=Star)](https://GitHub.com/petercorke/machinevision-toolbox-python/stargazers/) -->
@@ -123,7 +127,6 @@ Install the current code base from GitHub and pip install a link to that cloned
123
127
  from machinevisiontoolbox import Image
124
128
  mona = Image.Read("monalisa.png")
125
129
  mona.disp()
126
- mona.smooth(sigma=5).disp()
127
130
  ```
128
131
 
129
132
  ![Mona Lisa image](https://github.com/petercorke/machinevision-toolbox-python/raw/master/figs/mona.png)
@@ -0,0 +1,42 @@
1
+ machinevisiontoolbox/BagOfWords.py,sha256=kHAt6P5Tz5iWpP9N-fcdL3KTwimBqxu9QQ1WRs04Lzc,19680
2
+ machinevisiontoolbox/BundleAdjust.py,sha256=syBFkXwJcRWpNr0k6gu-J3shzH0ozbgOgwaZp844fqk,36081
3
+ machinevisiontoolbox/Camera.py,sha256=tRlRB7t9uBLe586-AfD9DoEXMNfOjwKIasok4jHjy7Y,135063
4
+ machinevisiontoolbox/ImageBlobs.py,sha256=WXrSw1udWTk3IqnFBrWUOQuIvQSep9on1aisM3M6WZ8,49166
5
+ machinevisiontoolbox/ImageColor.py,sha256=V4T_fs0EvFJegAQrNr-3pR7rg7Dye00g2V3JVEK4oOA,17111
6
+ machinevisiontoolbox/ImageConstants.py,sha256=osFF83O2AxKkQffNGBUjUoupRYfcZtRndeWaOPO6GpY,13307
7
+ machinevisiontoolbox/ImageCore.py,sha256=wOj7z1Eg252751x6gbjVJdzMfyr0qCNNe5r_xqFi080,79464
8
+ machinevisiontoolbox/ImageIO.py,sha256=412vI_OTvVvWcD5BFdc5GS-GUCkNnr4I86UDEehE70I,20600
9
+ machinevisiontoolbox/ImageLineFeatures.py,sha256=IlWSZOrvLnzvLx1vf4GuXb4Icpj214jz9FCDleguV9s,9104
10
+ machinevisiontoolbox/ImageMorph.py,sha256=oe4Tk_4TM96gExHAzdEb1UdOVgih-3U_Ylpm0r6Xrzw,23789
11
+ machinevisiontoolbox/ImageMultiview.py,sha256=wQWcq2Er-EzNNQ7_0mZRuID9VFh4rCjXPxZ-yMiQ-W4,14703
12
+ machinevisiontoolbox/ImagePointFeatures.py,sha256=zMDyRwJxlytgGIa25PMOTZk85v9LSX2zn7OpZC1Tsfg,76218
13
+ machinevisiontoolbox/ImageProcessing.py,sha256=GOWBAXQyTkgzhkJuTysBLbo0xEzLMqi73A_TfCG5L8g,37975
14
+ machinevisiontoolbox/ImageRegionFeatures.py,sha256=2eLwHnDLK8BpmkshrthpYrlaN7G6I-q8N6ioE8OC0Ig,22175
15
+ machinevisiontoolbox/ImageReshape.py,sha256=uStEtnnyVzqfC3rJCDWRo-nm1JjxvgMd9MrIFI94kZc,45673
16
+ machinevisiontoolbox/ImageSpatial.py,sha256=zTsA2puUDPHjU5ISHY6LyVaeby3vWJcqubduGNOxb8I,64761
17
+ machinevisiontoolbox/ImageWholeFeatures.py,sha256=Zgrt-xnncTY0WhqJtTqB8JbwJSroEpK-9HRaKVdGeMw,27698
18
+ machinevisiontoolbox/PointCloud.py,sha256=4m_G4_elZei_VZ84PPs-i5ceUwOXhcuZ9-1xRZdNDDA,18286
19
+ machinevisiontoolbox/Sources.py,sha256=gU_JJMEYiMhvPZkMODKSdsDUZPjwncu5U_yEkXY4nOE,28615
20
+ machinevisiontoolbox/VisualServo.py,sha256=PlHCz_jbvV1JFfDrePQQ7cP94Wr5nliulHtYEMGwJtw,59294
21
+ machinevisiontoolbox/__init__.py,sha256=tYSGLnUl2s2XY-H3Y3YfcyjGFVzpTIqrhAW7yDQ4yZg,1257
22
+ machinevisiontoolbox/camera_derivatives.py,sha256=uChdvsXC-25Cg7-xH7tIbxe3tcxxJGQ_nslSiCvnL88,17557
23
+ machinevisiontoolbox/fiducial.py,sha256=syC7iIz95nYBTr_njo4ZzLXOyAdAIqoAZq_wRVhyUHQ,1374
24
+ machinevisiontoolbox/newcameras.py,sha256=iQ8Fduiub4Clh1JIEVvQTXZVqXrmgzf0Y5iMPGTOW-w,1225
25
+ machinevisiontoolbox/base/__init__.py,sha256=ZEkTMuSMrmY04iOhhAPlb3YhteGuqQEcIF6l9mim5K8,1446
26
+ machinevisiontoolbox/base/color.py,sha256=syipdtbxUrHXFl0288HLMpY31khdCYcGeDwCoMj-MMk,54593
27
+ machinevisiontoolbox/base/data.py,sha256=s-A_BGuGpmft_3A_nr-kMow0repLJnXPFQah24aYbXM,5421
28
+ machinevisiontoolbox/base/esttheta.py,sha256=pYFguhXwo9FoaH0sRAXxrcEkECYttDPnHWBi1YMfISY,2323
29
+ machinevisiontoolbox/base/findpeaks.py,sha256=e0dcG6ZqHMwpzRFQrZH9-OITzhspi6Lq1TZoS37IPQY,10377
30
+ machinevisiontoolbox/base/graphics.py,sha256=WkqJPLKzZvSIJE5tFQ07Fa5dK8gBmJxGEvCwmxkVtrU,24663
31
+ machinevisiontoolbox/base/imageio.py,sha256=zaURDEM5JUDATDYd0o3EcEdHQ7OYXQw1rOwU02Cz-aU,37425
32
+ machinevisiontoolbox/base/meshgrid.py,sha256=JYuZaw33ZJZQqqSxW8W7jLwr9iGzuXLUa3UKSlb51oQ,2350
33
+ machinevisiontoolbox/base/shapes.py,sha256=2FmjeuDnehNF5ZmssFDawmblDpKhuVUI3CmXCcILJxg,9926
34
+ machinevisiontoolbox/base/types.py,sha256=3znb81yTFb7sLrgjgt0P5q5wZa9_iRZGw_hWbINhCxc,4716
35
+ machinevisiontoolbox/blocks/__init__.py,sha256=CH3psChJdDh3cnqDlZGf76C-TLFOKHJlQjBXSz8dnbY,104
36
+ machinevisiontoolbox/blocks/camera.py,sha256=qWT_LoDFcZkCAlRqQkRDzX0fr4EvkEgdtGo0QPoO_8s,9776
37
+ machinevisiontoolbox/blocks/test_blocks.py,sha256=qBU-gE1Q67CtBatX2t-tnJ7ALYNfacAj3yZt3ZgY-J8,1572
38
+ machinevision_toolbox_python-0.9.7.dist-info/LICENSE,sha256=niCzY_CzbIMKuUZlUkGimjrKp0vkLAtcwFmoSuSKrdw,1068
39
+ machinevision_toolbox_python-0.9.7.dist-info/METADATA,sha256=7aa8EnpO12J1c_YGxoz8zQlJvNaSvGh-GrKlLp2h3Rg,19553
40
+ machinevision_toolbox_python-0.9.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
41
+ machinevision_toolbox_python-0.9.7.dist-info/top_level.txt,sha256=HC0K-k55L-H_l8QzNMmP1_vLgBkdTrsM0Kj_rjRrulo,21
42
+ machinevision_toolbox_python-0.9.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -7,7 +7,6 @@ import cv2 as cv
7
7
 
8
8
  # TODO: remove top N% and bottom M% of words by frequency
9
9
  class BagOfWords:
10
-
11
10
  def __init__(self, images, k=2_000, nstopwords=0, attempts=1, seed=None):
12
11
  r"""
13
12
  Bag of words class
@@ -22,8 +21,8 @@ class BagOfWords:
22
21
  :type attempts: int, optional
23
22
 
24
23
  Bag of words is a powerful feature-based method for matching images
25
- from widely different viewpoints.
26
-
24
+ from widely different viewpoints.
25
+
27
26
  This class creates a bag of words from a sequence of images or a set of
28
27
  point features. In the former case, the features will have an ``.id``
29
28
  equal to the index of the image in the sequence. For the latter case,
@@ -45,12 +44,12 @@ class BagOfWords:
45
44
  of image features is assigned labels from the ``.centroids`` any with a
46
45
  label greater that ``.nstopwords`` is a stop word and can be discarded.
47
46
 
48
- :reference:
47
+ :reference:
49
48
  - Video Google: a text retrieval approach to object matching in videos
50
- J.Sivic and A.Zisserman,
51
- in Proc. Ninth IEEE Int. Conf. on Computer Vision,
49
+ J.Sivic and A.Zisserman,
50
+ in Proc. Ninth IEEE Int. Conf. on Computer Vision,
52
51
  pp.1470-1477, Oct. 2003.
53
- - Robotics, Vision & Control for Python, Section 12.4.2,
52
+ - Robotics, Vision & Control for Python, Section 12.4.2,
54
53
  P. Corke, Springer 2023.
55
54
 
56
55
  :seealso: :meth:`recall` :meth:`~machinevisiontoolbox.ImagePointFeatures.BaseFeature2D`
@@ -73,7 +72,7 @@ class BagOfWords:
73
72
 
74
73
  self._images = images
75
74
 
76
- # save the image id's
75
+ # save the image id's
77
76
  self._image_id = np.r_[features.id]
78
77
  self._nimages = self._image_id.max() + 1
79
78
  self._features = features
@@ -87,12 +86,13 @@ class BagOfWords:
87
86
  cv.setRNGSeed(seed)
88
87
 
89
88
  ret, labels, centroids = cv.kmeans(
90
- data=features._descriptor,
91
- K=k,
92
- bestLabels=None,
93
- criteria=criteria,
94
- attempts=attempts,
95
- flags=cv.KMEANS_RANDOM_CENTERS)
89
+ data=features._descriptor,
90
+ K=k,
91
+ bestLabels=None,
92
+ criteria=criteria,
93
+ attempts=attempts,
94
+ flags=cv.KMEANS_RANDOM_CENTERS,
95
+ )
96
96
 
97
97
  self._k = k
98
98
 
@@ -128,7 +128,7 @@ class BagOfWords:
128
128
  idf = np.log(N / ni)
129
129
 
130
130
  M = []
131
-
131
+
132
132
  for i in range(self.nimages):
133
133
  # number of words in this image
134
134
  nd = W[:, i].sum()
@@ -136,13 +136,13 @@ class BagOfWords:
136
136
  # word occurrence frequency
137
137
  nid = W[:, i]
138
138
 
139
- with np.errstate(divide='ignore', invalid='ignore'):
139
+ with np.errstate(divide="ignore", invalid="ignore"):
140
140
  v = nid / nd * idf
141
141
 
142
142
  v[~np.isfinite(v)] = 0
143
143
  M.append(v)
144
144
 
145
- self._word_freq_vectors = np.column_stack(M)
145
+ self._word_freq_vectors = np.column_stack(M)
146
146
  self._idf = idf
147
147
 
148
148
  def wwfv(self, i=None):
@@ -298,7 +298,7 @@ class BagOfWords:
298
298
  return s
299
299
 
300
300
  def _remove_stopwords(self, verbose=True):
301
- #BagOfWords.remove_stop Remove stop words
301
+ # BagOfWords.remove_stop Remove stop words
302
302
  #
303
303
  # B.remove_stop(N) removes the N most frequent words (the stop words)
304
304
  # from the self. All remaining words are renumbered so that the word
@@ -314,10 +314,12 @@ class BagOfWords:
314
314
 
315
315
  # unique_words will be [0,k)
316
316
  index = np.argsort(-freq) # sort descending order
317
- stopwords = unique_words[index[:self.nstopwords]] # array of stop words
317
+ stopwords = unique_words[index[: self.nstopwords]] # array of stop words
318
318
 
319
319
  stopfeatures = freq[stopwords].sum()
320
- print(f"Removing {stopfeatures} features ({stopfeatures/len(self.words) * 100:.1f}%) associated with {self.nstopwords} most frequent words")
320
+ print(
321
+ f"Removing {stopfeatures} features ({stopfeatures/len(self.words) * 100:.1f}%) associated with {self.nstopwords} most frequent words"
322
+ )
321
323
 
322
324
  k = np.full(index.shape, False, dtype=bool)
323
325
  k[stopwords] = True
@@ -334,7 +336,7 @@ class BagOfWords:
334
336
  words = np.array([mapdict[w] for w in self.words])
335
337
 
336
338
  self._labels = words
337
-
339
+
338
340
  # only retain the non stop words
339
341
  keep = words < self.nstopwords
340
342
  self._words = words[keep]
@@ -353,7 +355,7 @@ class BagOfWords:
353
355
  :return: confusion matrix
354
356
  :rtype: ndarray(M,N)
355
357
 
356
- The array has rows corresponding to the images in ``self`` and
358
+ The array has rows corresponding to the images in ``self`` and
357
359
  columns corresponding to the images in ``other``.
358
360
 
359
361
  :seealso: :meth:`.closest`
@@ -361,16 +363,18 @@ class BagOfWords:
361
363
  if isinstance(arg, np.ndarray):
362
364
  wwfv = arg
363
365
  sim = np.empty((wwfv.shape[1], self.nimages))
364
-
366
+
365
367
  for j, vj in enumerate(wwfv.T):
366
368
  for i in range(self.nimages):
367
369
  vi = self.wwfv(i)
368
370
 
369
- with np.errstate(divide='ignore', invalid='ignore'):
370
- sim[j, i] = np.dot(vi.ravel(), vj) / (np.linalg.norm(vi) * np.linalg.norm(vj))
371
+ with np.errstate(divide="ignore", invalid="ignore"):
372
+ sim[j, i] = np.dot(vi.ravel(), vj) / (
373
+ np.linalg.norm(vi) * np.linalg.norm(vj)
374
+ )
371
375
  else:
372
376
  images = arg
373
- if not hasattr(images, '__iter__'):
377
+ if not hasattr(images, "__iter__"):
374
378
  # if not iterable like a FileCollection or VideoFile turn the image
375
379
  # into a list of 1
376
380
  images = [images]
@@ -378,7 +382,7 @@ class BagOfWords:
378
382
  # similarity has bag index as column, query index as row
379
383
  sim = np.empty((len(images), self.nimages))
380
384
  for j, image in enumerate(images):
381
- features = image.SIFT(id='image')
385
+ features = image.SIFT(id="image")
382
386
 
383
387
  # assign features to given cluster centroids
384
388
  # the elements of matches are:
@@ -393,11 +397,11 @@ class BagOfWords:
393
397
 
394
398
  # word occurrence frequency
395
399
  nid = BagOfWords._word_freq_vector(words, self.k - self.nstopwords)
396
-
400
+
397
401
  # number of words in this image
398
402
  nd = nid.sum()
399
403
 
400
- with np.errstate(divide='ignore', invalid='ignore'):
404
+ with np.errstate(divide="ignore", invalid="ignore"):
401
405
  v2 = nid / nd * self._idf
402
406
 
403
407
  v2[~np.isfinite(v2)] = 0
@@ -405,9 +409,11 @@ class BagOfWords:
405
409
  for i in range(self.nimages):
406
410
  v1 = self.wwfv(i).ravel()
407
411
 
408
- with np.errstate(divide='ignore', invalid='ignore'):
409
- sim[j, i] = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
410
-
412
+ with np.errstate(divide="ignore", invalid="ignore"):
413
+ sim[j, i] = np.dot(v1, v2) / (
414
+ np.linalg.norm(v1) * np.linalg.norm(v2)
415
+ )
416
+
411
417
  if sim.shape[0] == 1:
412
418
  sim = sim[0, :]
413
419
  return sim
@@ -464,7 +470,7 @@ class BagOfWords:
464
470
  the frequency of the corresponding word across all images.
465
471
  """
466
472
 
467
- #BagOfWords.wordfreq Word frequency statistics
473
+ # BagOfWords.wordfreq Word frequency statistics
468
474
  #
469
475
  # [W,N] = B.wordfreq[] is a vector of word labels W and the corresponding
470
476
  # elements of N are the number of occurrences of that word.
@@ -485,7 +491,7 @@ class BagOfWords:
485
491
  """
486
492
  s = S[:, i]
487
493
  index = np.argsort(-s)
488
-
494
+
489
495
  return index, s[index]
490
496
 
491
497
  def contains(self, word):
@@ -500,15 +506,16 @@ class BagOfWords:
500
506
  :seealso: :meth:`exemplars`
501
507
  """
502
508
  return np.unique(self._image_id[self.words == word])
503
-
504
509
 
505
- def exemplars(self, word, images=None, maxperimage=2, columns=10, max=None, width=50, **kwargs):
510
+ def exemplars(
511
+ self, word, images=None, maxperimage=2, columns=10, max=None, width=50, **kwargs
512
+ ):
506
513
  """
507
514
  Composite image containing exemplars of specified word
508
515
 
509
516
  :param word: visual word label
510
517
  :type word: int
511
- :param images: the set of images corresponding to this bag, only
518
+ :param images: the set of images corresponding to this bag, only
512
519
  required if the bag was constructed from features not images.
513
520
  :param maxperimage: maximum number of exemplars drawn from any one image, defaults to 2
514
521
  :type maxperimage: int, optional
@@ -523,8 +530,8 @@ class BagOfWords:
523
530
 
524
531
  Produces a grid of examples of a particular visual word.
525
532
 
526
- :seealso: :meth:`contains`
527
- :meth:`~machinevisiontoolbox.ImagePointFeatures.BaseFeature2D.support`
533
+ :seealso: :meth:`contains`
534
+ :meth:`~machinevisiontoolbox.ImagePointFeatures.BaseFeature2D.support`
528
535
  :meth:`~machinevisiontoolbox.Image.Tile`
529
536
  """
530
537
  from machinevisiontoolbox import Image
@@ -545,6 +552,7 @@ class BagOfWords:
545
552
 
546
553
  return Image.Tile(exemplars, columns=columns, **kwargs)
547
554
 
555
+
548
556
  if __name__ == "__main__":
549
557
 
550
558
  import numpy as np
@@ -554,7 +562,7 @@ if __name__ == "__main__":
554
562
 
555
563
  cv.setRNGSeed(0)
556
564
 
557
- images = ImageCollection('campus/*.png', mono=True)
565
+ images = ImageCollection("campus/*.png", mono=True)
558
566
 
559
567
  features = []
560
568
  for image in images:
@@ -570,7 +578,6 @@ if __name__ == "__main__":
570
578
 
571
579
  Image.Tile(ex, columns=20).disp(plain=True)
572
580
 
573
-
574
581
  feature = features[108]
575
582
  print(feature)
576
583
 
@@ -600,7 +607,7 @@ if __name__ == "__main__":
600
607
 
601
608
  sim_8 = bag.similarity(images[8]).ravel()
602
609
  print(sim_8)
603
- k = np.argsort(-sim_8);
610
+ k = np.argsort(-sim_8)
604
611
  print(np.c_[sim_8[k], k])
605
612
 
606
613
  ss = []
@@ -608,13 +615,13 @@ if __name__ == "__main__":
608
615
  ss.append(images[k[i]])
609
616
  Image.Tile(ss, columns=2).disp()
610
617
 
611
- holdout = ImageCollection("campus/holdout/*.png", mono=True);
618
+ holdout = ImageCollection("campus/holdout/*.png", mono=True)
612
619
 
613
620
  sim = bag.similarity(holdout)
614
621
 
615
622
  sim_2 = bag.similarity(holdout[2]).ravel()
616
623
  print(sim_2)
617
- k = np.argsort(-sim_2);
624
+ k = np.argsort(-sim_2)
618
625
  print(np.c_[sim_2[k], k])
619
626
 
620
627
  ss = [holdout[2]]
@@ -623,7 +630,3 @@ if __name__ == "__main__":
623
630
  Image.Tile(ss, columns=2).disp()
624
631
 
625
632
  Image(sim).disp(block=True)
626
-
627
-
628
-
629
-