Region.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Region &#8212; Image Features Extraction 1.0.0 documentation</title>
  7. <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
  8. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../',
  12. VERSION: '1.0.0',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true,
  16. SOURCELINK_SUFFIX: '.txt'
  17. };
  18. </script>
  19. <script type="text/javascript" src="../_static/jquery.js"></script>
  20. <script type="text/javascript" src="../_static/underscore.js"></script>
  21. <script type="text/javascript" src="../_static/doctools.js"></script>
  22. <link rel="index" title="Index" href="../genindex.html" />
  23. <link rel="search" title="Search" href="../search.html" />
  24. <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  25. <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
  26. </head>
  27. <body>
  28. <div class="document">
  29. <div class="documentwrapper">
  30. <div class="bodywrapper">
  31. <div class="body" role="main">
  32. <h1>Source code for Region</h1><div class="highlight"><pre>
  33. <span></span><span class="kn">from</span> <span class="nn">image_features_extraction</span> <span class="k">import</span> <span class="n">MyException</span>
  34. <div class="viewcode-block" id="Region"><a class="viewcode-back" href="../code.html#Region.Region">[docs]</a><span class="k">class</span> <span class="nc">Region</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  35. <span class="sd">&quot;&quot;&quot;</span>
  36. <span class="sd"> Object refering to a single image region</span>
  37. <span class="sd"> &quot;&quot;&quot;</span>
  38. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj_region</span><span class="p">):</span>
  39. <span class="k">if</span> <span class="n">obj_region</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  40. <span class="k">raise</span> <span class="n">MyException</span><span class="o">.</span><span class="n">MyException</span>
  41. <span class="bp">self</span><span class="o">.</span><span class="n">__obj_region</span> <span class="o">=</span> <span class="n">obj_region</span>
  42. <div class="viewcode-block" id="Region.prop_value"><a class="viewcode-back" href="../code.html#Region.Region.prop_value">[docs]</a> <span class="k">def</span> <span class="nf">prop_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">):</span>
  43. <span class="sd">&quot;&quot;&quot;</span>
  44. <span class="sd"> Measure the specified property name (e.g., &#39;area&#39;)</span>
  45. <span class="sd"> :param prop_name: name of the property to measure (e.g, &#39;area&#39;)</span>
  46. <span class="sd"> :type prop_name: string</span>
  47. <span class="sd"> :returns: value of the property name</span>
  48. <span class="sd"> :rtype: int,float,list</span>
  49. <span class="sd"> :example:</span>
  50. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  51. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  52. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  53. <span class="sd"> &gt;&gt;&gt; regs = img.Regions()</span>
  54. <span class="sd"> &gt;&gt;&gt; reg = regs.Region()</span>
  55. <span class="sd"> &gt;&gt;&gt; area = reg.prop_value(&#39;area&#39;)</span>
  56. <span class="sd"> The following properties can be accessed as attributes or keys:</span>
  57. <span class="sd"> **area** : int</span>
  58. <span class="sd"> Number of pixels of region.</span>
  59. <span class="sd"> **bbox** : tuple</span>
  60. <span class="sd"> Bounding box ``(min_row, min_col, max_row, max_col)``.</span>
  61. <span class="sd"> Pixels belonging to the bounding box are in the half-open interval</span>
  62. <span class="sd"> ``[min_row; max_row)`` and ``[min_col; max_col)``.</span>
  63. <span class="sd"> **bbox_area** : int</span>
  64. <span class="sd"> Number of pixels of bounding box.</span>
  65. <span class="sd"> **centroid** : array</span>
  66. <span class="sd"> Centroid coordinate tuple ``(row, col)``.</span>
  67. <span class="sd"> **convex_area** : int</span>
  68. <span class="sd"> Number of pixels of convex hull image.</span>
  69. <span class="sd"> **convex_image** : (H, J) ndarray</span>
  70. <span class="sd"> Binary convex hull image which has the same size as bounding box.</span>
  71. <span class="sd"> **coords** : (N, 2) ndarray</span>
  72. <span class="sd"> Coordinate list ``(row, col)`` of the region.</span>
  73. <span class="sd"> **eccentricity** : float</span>
  74. <span class="sd"> Eccentricity of the ellipse that has the same second-moments as the</span>
  75. <span class="sd"> region. The eccentricity is the ratio of the focal distance</span>
  76. <span class="sd"> (distance between focal points) over the major axis length.</span>
  77. <span class="sd"> The value is in the interval [0, 1).</span>
  78. <span class="sd"> When it is 0, the ellipse becomes a circle.</span>
  79. <span class="sd"> **equivalent_diameter** : float</span>
  80. <span class="sd"> The diameter of a circle with the same area as the region.</span>
  81. <span class="sd"> **euler_number** : int</span>
  82. <span class="sd"> Euler characteristic of region. Computed as number of objects (= 1)</span>
  83. <span class="sd"> subtracted by number of holes (8-connectivity).</span>
  84. <span class="sd"> **extent** : float</span>
  85. <span class="sd"> Ratio of pixels in the region to pixels in the total bounding box.</span>
  86. <span class="sd"> Computed as ``area / (rows * cols)``</span>
  87. <span class="sd"> **filled_area** : int</span>
  88. <span class="sd"> Number of pixels of filled region.</span>
  89. <span class="sd"> **filled_image** : (H, J) ndarray</span>
  90. <span class="sd"> Binary region image with filled holes which has the same size as</span>
  91. <span class="sd"> bounding box.</span>
  92. <span class="sd"> **image** : (H, J) ndarray</span>
  93. <span class="sd"> Sliced binary region image which has the same size as bounding box.</span>
  94. <span class="sd"> **inertia_tensor** : (2, 2) ndarray</span>
  95. <span class="sd"> Inertia tensor of the region for the rotation around its mass.</span>
  96. <span class="sd"> **inertia_tensor_eigvals** : tuple</span>
  97. <span class="sd"> The two eigen values of the inertia tensor in decreasing order.</span>
  98. <span class="sd"> **intensity_image** : ndarray</span>
  99. <span class="sd"> Image inside region bounding box.</span>
  100. <span class="sd"> **label** : int</span>
  101. <span class="sd"> The label in the labeled input image.</span>
  102. <span class="sd"> **local_centroid** : array</span>
  103. <span class="sd"> Centroid coordinate tuple ``(row, col)``, relative to region bounding</span>
  104. <span class="sd"> box.</span>
  105. <span class="sd"> **major_axis_length** : float</span>
  106. <span class="sd"> The length of the major axis of the ellipse that has the same</span>
  107. <span class="sd"> normalized second central moments as the region.</span>
  108. <span class="sd"> **max_intensity** : float</span>
  109. <span class="sd"> Value with the greatest intensity in the region.</span>
  110. <span class="sd"> **mean_intensity** : float</span>
  111. <span class="sd"> Value with the mean intensity in the region.</span>
  112. <span class="sd"> **min_intensity** : float</span>
  113. <span class="sd"> Value with the least intensity in the region.</span>
  114. <span class="sd"> **minor_axis_length** : float</span>
  115. <span class="sd"> The length of the minor axis of the ellipse that has the same</span>
  116. <span class="sd"> normalized second central moments as the region.</span>
  117. <span class="sd"> **moments** : (3, 3) ndarray</span>
  118. <span class="sd"> Spatial moments up to 3rd order::</span>
  119. <span class="sd"> m_ji = sum{ array(x, y) * x^j * y^i }</span>
  120. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region.</span>
  121. <span class="sd"> **moments_central** : (3, 3) ndarray</span>
  122. <span class="sd"> Central moments (translation invariant) up to 3rd order::</span>
  123. <span class="sd"> mu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }</span>
  124. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region,</span>
  125. <span class="sd"> and `x_c` and `y_c` are the coordinates of the region&#39;s centroid.</span>
  126. <span class="sd"> **moments_hu** : tuple</span>
  127. <span class="sd"> Hu moments (translation, scale and rotation invariant).</span>
  128. <span class="sd"> **moments_normalized** : (3, 3) ndarray</span>
  129. <span class="sd"> Normalized moments (translation and scale invariant) up to 3rd order::</span>
  130. <span class="sd"> nu_ji = mu_ji / m_00^[(i+j)/2 + 1]</span>
  131. <span class="sd"> where `m_00` is the zeroth spatial moment.</span>
  132. <span class="sd"> **orientation** : float</span>
  133. <span class="sd"> Angle between the X-axis and the major axis of the ellipse that has</span>
  134. <span class="sd"> the same second-moments as the region. Ranging from `-pi/2` to</span>
  135. <span class="sd"> `pi/2` in counter-clockwise direction.</span>
  136. <span class="sd"> **perimeter** : float</span>
  137. <span class="sd"> Perimeter of object which approximates the contour as a line</span>
  138. <span class="sd"> through the centers of border pixels using a 4-connectivity.</span>
  139. <span class="sd"> **solidity** : float</span>
  140. <span class="sd"> Ratio of pixels in the region to pixels of the convex hull image.</span>
  141. <span class="sd"> **weighted_centroid** : array</span>
  142. <span class="sd"> Centroid coordinate tuple ``(row, col)`` weighted with intensity</span>
  143. <span class="sd"> image.</span>
  144. <span class="sd"> **weighted_local_centroid** : array</span>
  145. <span class="sd"> Centroid coordinate tuple ``(row, col)``, relative to region bounding</span>
  146. <span class="sd"> box, weighted with intensity image.</span>
  147. <span class="sd"> **weighted_moments** : (3, 3) ndarray</span>
  148. <span class="sd"> Spatial moments of intensity image up to 3rd order::</span>
  149. <span class="sd"> wm_ji = sum{ array(x, y) * x^j * y^i }</span>
  150. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region.</span>
  151. <span class="sd"> **weighted_moments_central** : (3, 3) ndarray</span>
  152. <span class="sd"> Central moments (translation invariant) of intensity image up to</span>
  153. <span class="sd"> 3rd order::</span>
  154. <span class="sd"> wmu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }</span>
  155. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region,</span>
  156. <span class="sd"> and `x_c` and `y_c` are the coordinates of the region&#39;s weighted</span>
  157. <span class="sd"> centroid.</span>
  158. <span class="sd"> **weighted_moments_hu** : tuple</span>
  159. <span class="sd"> Hu moments (translation, scale and rotation invariant) of intensity</span>
  160. <span class="sd"> image.</span>
  161. <span class="sd"> **weighted_moments_normalized** : (3, 3) ndarray</span>
  162. <span class="sd"> Normalized moments (translation and scale invariant) of intensity</span>
  163. <span class="sd"> image up to 3rd order::</span>
  164. <span class="sd"> wnu_ji = wmu_ji / wm_00^[(i+j)/2 + 1]</span>
  165. <span class="sd"> where ``wm_00`` is the zeroth spatial moment (intensity-weighted area).</span>
  166. <span class="sd"> &quot;&quot;&quot;</span>
  167. <span class="k">try</span><span class="p">:</span>
  168. <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__obj_region</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">)</span>
  169. <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  170. <span class="nb">print</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">args</span><span class="p">)</span>
  171. <span class="k">return</span> <span class="kc">None</span></div></div>
  172. </pre></div>
  173. </div>
  174. </div>
  175. </div>
  176. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  177. <div class="sphinxsidebarwrapper">
  178. <h1 class="logo"><a href="../index.html">Image Features Extraction</a></h1>
  179. <h3>Navigation</h3>
  180. <ul>
  181. <li class="toctree-l1"><a class="reference internal" href="../tutorial.html">Tutorial</a></li>
  182. <li class="toctree-l1"><a class="reference internal" href="../code.html">Classes/Modules</a></li>
  183. </ul>
  184. <div class="relations">
  185. <h3>Related Topics</h3>
  186. <ul>
  187. <li><a href="../index.html">Documentation overview</a><ul>
  188. <li><a href="index.html">Module code</a><ul>
  189. </ul></li>
  190. </ul></li>
  191. </ul>
  192. </div>
  193. <div id="searchbox" style="display: none" role="search">
  194. <h3>Quick search</h3>
  195. <form class="search" action="../search.html" method="get">
  196. <div><input type="text" name="q" /></div>
  197. <div><input type="submit" value="Go" /></div>
  198. <input type="hidden" name="check_keywords" value="yes" />
  199. <input type="hidden" name="area" value="default" />
  200. </form>
  201. </div>
  202. <script type="text/javascript">$('#searchbox').show(0);</script>
  203. </div>
  204. </div>
  205. <div class="clearer"></div>
  206. </div>
  207. <div class="footer">
  208. &copy;2017, Remigio Picone.
  209. |
  210. Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.3</a>
  211. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
  212. </div>
  213. </body>
  214. </html>