Image.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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>Image &#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 Image</h1><div class="highlight"><pre>
  33. <span></span>
  34. <span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
  35. <span class="kn">import</span> <span class="nn">scipy.misc</span> <span class="k">as</span> <span class="nn">sm</span>
  36. <span class="kn">from</span> <span class="nn">skimage.measure</span> <span class="k">import</span> <span class="n">label</span>
  37. <span class="kn">from</span> <span class="nn">skimage.segmentation</span> <span class="k">import</span> <span class="n">clear_border</span>
  38. <span class="kn">from</span> <span class="nn">skimage.color</span> <span class="k">import</span> <span class="n">label2rgb</span>
  39. <span class="kn">from</span> <span class="nn">skimage.measure</span> <span class="k">import</span> <span class="n">label</span><span class="p">,</span> <span class="n">regionprops</span>
  40. <span class="kn">from</span> <span class="nn">skimage</span> <span class="k">import</span> <span class="n">filters</span><span class="p">,</span> <span class="n">io</span>
  41. <span class="kn">from</span> <span class="nn">image_features_extraction</span> <span class="k">import</span> <span class="n">Regions</span>
  42. <span class="kn">from</span> <span class="nn">image_features_extraction</span> <span class="k">import</span> <span class="n">MyException</span>
  43. <span class="kn">from</span> <span class="nn">image_features_extraction</span> <span class="k">import</span> <span class="n">Features</span>
  44. <span class="kn">from</span> <span class="nn">image_features_extraction</span> <span class="k">import</span> <span class="n">Utils</span>
  45. <span class="kn">import</span> <span class="nn">Voronoi_Features.Voronoi</span> <span class="k">as</span> <span class="nn">VF</span>
  46. <div class="viewcode-block" id="Image"><a class="viewcode-back" href="../code.html#Image.Image">[docs]</a><span class="k">class</span> <span class="nc">Image</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  47. <span class="sd">&quot;&quot;&quot;</span>
  48. <span class="sd"> This class instantiate an object Image through the :class:`Images` and refers to a specific file image</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"> &quot;&quot;&quot;</span>
  54. <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">full_name</span><span class="p">):</span>
  55. <span class="bp">self</span><span class="o">.</span><span class="n">__full_file_name</span> <span class="o">=</span> <span class="n">full_name</span>
  56. <span class="bp">self</span><span class="o">.</span><span class="n">__regions</span> <span class="o">=</span> <span class="kc">None</span>
  57. <span class="bp">self</span><span class="o">.</span><span class="n">__regionsprops</span> <span class="o">=</span> <span class="kc">None</span>
  58. <span class="bp">self</span><span class="o">.</span><span class="n">__image_intensity</span> <span class="o">=</span> <span class="kc">None</span>
  59. <span class="bp">self</span><span class="o">.</span><span class="n">__image</span> <span class="o">=</span> <span class="kc">None</span>
  60. <span class="bp">self</span><span class="o">.</span><span class="n">__image_semented</span> <span class="o">=</span> <span class="kc">None</span>
  61. <span class="k">try</span><span class="p">:</span>
  62. <span class="c1"># load image and segment</span>
  63. <span class="bp">self</span><span class="o">.</span><span class="n">__image</span> <span class="o">=</span> <span class="n">io</span><span class="o">.</span><span class="n">imread</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__full_file_name</span><span class="p">)</span>
  64. <span class="bp">self</span><span class="o">.</span><span class="n">__image_semented</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_regions</span><span class="p">()</span>
  65. <span class="bp">self</span><span class="o">.</span><span class="n">__regionsprops</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_regionsprop</span><span class="p">()</span>
  66. <span class="bp">self</span><span class="o">.</span><span class="n">__centroids</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prop_values</span><span class="p">(</span><span class="s1">&#39;centroid&#39;</span><span class="p">)</span>
  67. <span class="k">except</span> <span class="n">MyException</span><span class="o">.</span><span class="n">MyException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  68. <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>
  69. <div class="viewcode-block" id="Image.Voronoi"><a class="viewcode-back" href="../code.html#Image.Image.Voronoi">[docs]</a> <span class="k">def</span> <span class="nf">Voronoi</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  70. <span class="sd">&quot;&quot;&quot;</span>
  71. <span class="sd"> Image Voronoi diagram (refer to documentaiton of my package Voronoi_Features in my github )</span>
  72. <span class="sd"> :return: Voronoi object for the current image</span>
  73. <span class="sd"> :rtype: Voronoi object</span>
  74. <span class="sd"> &gt;&gt;&gt; import matplotlib.pyplot as plt</span>
  75. <span class="sd"> &gt;&gt;&gt;</span>
  76. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  77. <span class="sd"> &gt;&gt;&gt;</span>
  78. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  79. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  80. <span class="sd"> &gt;&gt;&gt;</span>
  81. <span class="sd"> &gt;&gt;&gt; voro = img.Voronoi()</span>
  82. <span class="sd"> &gt;&gt;&gt; # show voronoi diagram</span>
  83. <span class="sd"> &gt;&gt;&gt; fig = plt.figure(figsize=(20,20))</span>
  84. <span class="sd"> &gt;&gt;&gt; plt.imshow(vor.get_voronoi_map(), cmap=plt.get_cmap(&#39;jet&#39;))</span>
  85. <span class="sd"> &quot;&quot;&quot;</span>
  86. <span class="k">return</span> <span class="n">VF</span><span class="o">.</span><span class="n">Voronoi</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__centroids</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">__image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">__image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span></div>
  87. <div class="viewcode-block" id="Image.width"><a class="viewcode-back" href="../code.html#Image.Image.width">[docs]</a> <span class="k">def</span> <span class="nf">width</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  88. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></div>
  89. <div class="viewcode-block" id="Image.height"><a class="viewcode-back" href="../code.html#Image.Image.height">[docs]</a> <span class="k">def</span> <span class="nf">height</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  90. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__image</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>
  91. <div class="viewcode-block" id="Image.file_name"><a class="viewcode-back" href="../code.html#Image.Image.file_name">[docs]</a> <span class="k">def</span> <span class="nf">file_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  92. <span class="sd">&quot;&quot;&quot;</span>
  93. <span class="sd"> full file name of the image</span>
  94. <span class="sd"> :returns: file name</span>
  95. <span class="sd"> :rtype: string</span>
  96. <span class="sd"> &quot;&quot;&quot;</span>
  97. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__full_file_name</span></div>
  98. <div class="viewcode-block" id="Image.set_image_intensity"><a class="viewcode-back" href="../code.html#Image.Image.set_image_intensity">[docs]</a> <span class="k">def</span> <span class="nf">set_image_intensity</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image_intensity</span><span class="p">):</span>
  99. <span class="sd">&quot;&quot;&quot;</span>
  100. <span class="sd"> Sets the image to measurs image&#39;s region intensity properties (e.g, mean_intensity)</span>
  101. <span class="sd"> : param image_intensity: Image object for intensity measurement</span>
  102. <span class="sd"> : type image_intensity: Object Image</span>
  103. <span class="sd"> :returns: the set Image object for intensity measurement</span>
  104. <span class="sd"> :rtype: Object Image</span>
  105. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  106. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  107. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1) # this is the binary image used for segmentation</span>
  108. <span class="sd"> &gt;&gt;&gt; img_intensity = imgs.item(0) # this is the original image on which to measure intensities</span>
  109. <span class="sd"> &gt;&gt;&gt; img.set_image_intensity(img_intensity)</span>
  110. <span class="sd"> &gt;&gt;&gt; features = IMG.features([&#39;label&#39;, &#39;area&#39;,&#39;perimeter&#39;, &#39;centroid&#39;,&#39;major_axis_length&#39;, &#39;moments&#39;,&#39;mean_intensity&#39;], class_value=5)</span>
  111. <span class="sd"> &quot;&quot;&quot;</span>
  112. <span class="bp">self</span><span class="o">.</span><span class="n">__image_intensity</span> <span class="o">=</span> <span class="n">image_intensity</span><span class="o">.</span><span class="n">__image</span>
  113. <span class="bp">self</span><span class="o">.</span><span class="n">__regionsprops</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_regionsprop</span><span class="p">()</span></div>
  114. <div class="viewcode-block" id="Image.regions"><a class="viewcode-back" href="../code.html#Image.Image.regions">[docs]</a> <span class="k">def</span> <span class="nf">regions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  115. <span class="sd">&quot;&quot;&quot;</span>
  116. <span class="sd"> regions(...) returns the Object Regions</span>
  117. <span class="sd"> :returns: :class:`Regions`</span>
  118. <span class="sd"> :rtype: string</span>
  119. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  120. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  121. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  122. <span class="sd"> &gt;&gt;&gt; regs = img.Regions()</span>
  123. <span class="sd"> &quot;&quot;&quot;</span>
  124. <span class="k">try</span><span class="p">:</span>
  125. <span class="k">return</span> <span class="n">Regions</span><span class="o">.</span><span class="n">Regions</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__image_semented</span><span class="p">)</span> <span class="c1"># (self.__get_regions())</span>
  126. <span class="k">except</span> <span class="n">MyException</span><span class="o">.</span><span class="n">MyException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  127. <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>
  128. <span class="k">return</span> <span class="kc">None</span></div>
  129. <span class="k">def</span> <span class="nf">__get_regions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  130. <span class="c1"># apply thresholding</span>
  131. <span class="n">val</span> <span class="o">=</span> <span class="n">filters</span><span class="o">.</span><span class="n">threshold_otsu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__image</span><span class="p">)</span>
  132. <span class="c1"># segmentation</span>
  133. <span class="n">image_thresh</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__image</span> <span class="o">&gt;</span> <span class="n">val</span>
  134. <span class="c1"># returns the single segmented elements of the image</span>
  135. <span class="n">image_segment</span> <span class="o">=</span> <span class="n">label</span><span class="p">(</span><span class="n">image_thresh</span><span class="p">)</span>
  136. <span class="c1"># removes the image elements at the borde</span>
  137. <span class="k">return</span> <span class="n">clear_border</span><span class="p">(</span><span class="n">image_segment</span><span class="p">)</span>
  138. <span class="c1">#def __get_mask(self, redo=False):</span>
  139. <span class="c1"># if redo == False:</span>
  140. <span class="c1"># return self.__mask</span>
  141. <span class="c1"># # ithresholding to build the map</span>
  142. <span class="c1"># val = filters.threshold_otsu(self.__image)</span>
  143. <span class="c1"># # cretes the mask</span>
  144. <span class="c1"># return self.__image &gt; val</span>
  145. <span class="k">def</span> <span class="nf">__get_regionsprop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  146. <span class="k">return</span> <span class="n">regionprops</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__get_regions</span><span class="p">(),</span> <span class="n">intensity_image</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__image_intensity</span><span class="p">)</span>
  147. <div class="viewcode-block" id="Image.get_image_segmentation"><a class="viewcode-back" href="../code.html#Image.Image.get_image_segmentation">[docs]</a> <span class="k">def</span> <span class="nf">get_image_segmentation</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  148. <span class="sd">&quot;&quot;&quot;</span>
  149. <span class="sd"> Builds the image with mask overlay to show the segmentation</span>
  150. <span class="sd"> :returns: The image in RGB format, in a 3-D array of shape (.., .., 3).</span>
  151. <span class="sd"> :rtype: ndarray</span>
  152. <span class="sd"> &quot;&quot;&quot;</span>
  153. <span class="k">try</span><span class="p">:</span>
  154. <span class="k">return</span> <span class="n">label2rgb</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__get_regions</span><span class="p">(),</span> <span class="n">image</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__image</span><span class="p">)</span>
  155. <span class="k">except</span> <span class="n">MyException</span><span class="o">.</span><span class="n">MyException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  156. <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>
  157. <span class="k">return</span> <span class="kc">None</span></div>
  158. <div class="viewcode-block" id="Image.features"><a class="viewcode-back" href="../code.html#Image.Image.features">[docs]</a> <span class="k">def</span> <span class="nf">features</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">features_list</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
  159. <span class="sd">&quot;&quot;&quot;</span>
  160. <span class="sd"> Returns a table with all values for the property names given in input, and supplies an</span>
  161. <span class="sd"> additional parameter for feature classification</span>
  162. <span class="sd"> :param features_list: list of property/measure names (e.g, &#39;area&#39;, &#39;centroid&#39;, etc )</span>
  163. <span class="sd"> :type features_list: List</span>
  164. <span class="sd"> :param prefix: prefix for features name</span>
  165. <span class="sd"> :type prefix: string</span>
  166. <span class="sd"> :param suffix: prefix for features name</span>
  167. <span class="sd"> :type suffix: string</span>
  168. <span class="sd"> :returns: Features Object</span>
  169. <span class="sd"> :rtype: Features Object</span>
  170. <span class="sd"> :example:</span>
  171. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  172. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  173. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  174. <span class="sd"> &gt;&gt;&gt; feature = img.get_features([&#39;label&#39;, &#39;area&#39;,&#39;perimeter&#39;, &#39;centroid&#39;])</span>
  175. <span class="sd"> &quot;&quot;&quot;</span>
  176. <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">()</span>
  177. <span class="k">try</span><span class="p">:</span>
  178. <span class="c1">#self.__regionsprops = self.__get_regionsprop()</span>
  179. <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__regionsprops</span><span class="p">)</span>
  180. <span class="n">df</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">n</span><span class="p">)</span>
  181. <span class="k">for</span> <span class="n">feature_name</span> <span class="ow">in</span> <span class="n">features_list</span><span class="p">:</span>
  182. <span class="n">values</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prop_values</span><span class="p">(</span><span class="n">feature_name</span><span class="p">)</span>
  183. <span class="n">Utils</span><span class="o">.</span><span class="n">insert_values</span><span class="p">(</span><span class="n">prefix</span> <span class="o">+</span> <span class="n">feature_name</span> <span class="o">+</span> <span class="n">suffix</span><span class="p">,</span> <span class="n">df</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
  184. <span class="k">return</span> <span class="n">Features</span><span class="o">.</span><span class="n">Features</span><span class="p">(</span><span class="n">df</span><span class="p">)</span>
  185. <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  186. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;one or more input labels might be wrong:</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
  187. <span class="k">return</span> <span class="kc">None</span></div>
  188. <div class="viewcode-block" id="Image.prop_values"><a class="viewcode-back" href="../code.html#Image.Image.prop_values">[docs]</a> <span class="k">def</span> <span class="nf">prop_values</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">):</span>
  189. <span class="sd">&quot;&quot;&quot;</span>
  190. <span class="sd"> Measure the values of the specified property/measure name (e.g., &#39;area&#39;) for all</span>
  191. <span class="sd"> elements contained in the object Regions.</span>
  192. <span class="sd"> :param prop_name: name of the property to measure (e.g, &#39;area&#39;)</span>
  193. <span class="sd"> :type prop_name: string</span>
  194. <span class="sd"> :returns: property name values</span>
  195. <span class="sd"> :rtype: List</span>
  196. <span class="sd"> :example:</span>
  197. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  198. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  199. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  200. <span class="sd"> &gt;&gt;&gt; regs = img.Regions()</span>
  201. <span class="sd"> &gt;&gt;&gt; areas = regs.prop_values(&#39;area&#39;)</span>
  202. <span class="sd"> The following properties can be accessed as attributes or keys:</span>
  203. <span class="sd"> **area** : int</span>
  204. <span class="sd"> Number of pixels of region.</span>
  205. <span class="sd"> **bbox** : tuple</span>
  206. <span class="sd"> Bounding box ``(min_row, min_col, max_row, max_col)``.</span>
  207. <span class="sd"> Pixels belonging to the bounding box are in the half-open interval</span>
  208. <span class="sd"> ``[min_row; max_row)`` and ``[min_col; max_col)``.</span>
  209. <span class="sd"> **bbox_area** : int</span>
  210. <span class="sd"> Number of pixels of bounding box.</span>
  211. <span class="sd"> **centroid** : array</span>
  212. <span class="sd"> Centroid coordinate tuple ``(row, col)``.</span>
  213. <span class="sd"> **convex_area** : int</span>
  214. <span class="sd"> Number of pixels of convex hull image.</span>
  215. <span class="sd"> **convex_image** : (H, J) ndarray</span>
  216. <span class="sd"> Binary convex hull image which has the same size as bounding box.</span>
  217. <span class="sd"> **coords** : (N, 2) ndarray</span>
  218. <span class="sd"> Coordinate list ``(row, col)`` of the region.</span>
  219. <span class="sd"> **eccentricity** : float</span>
  220. <span class="sd"> Eccentricity of the ellipse that has the same second-moments as the</span>
  221. <span class="sd"> region. The eccentricity is the ratio of the focal distance</span>
  222. <span class="sd"> (distance between focal points) over the major axis length.</span>
  223. <span class="sd"> The value is in the interval [0, 1).</span>
  224. <span class="sd"> When it is 0, the ellipse becomes a circle.</span>
  225. <span class="sd"> **equivalent_diameter** : float</span>
  226. <span class="sd"> The diameter of a circle with the same area as the region.</span>
  227. <span class="sd"> **euler_number** : int</span>
  228. <span class="sd"> Euler characteristic of region. Computed as number of objects (= 1)</span>
  229. <span class="sd"> subtracted by number of holes (8-connectivity).</span>
  230. <span class="sd"> **extent** : float</span>
  231. <span class="sd"> Ratio of pixels in the region to pixels in the total bounding box.</span>
  232. <span class="sd"> Computed as ``area / (rows * cols)``</span>
  233. <span class="sd"> **filled_area** : int</span>
  234. <span class="sd"> Number of pixels of filled region.</span>
  235. <span class="sd"> **filled_image** : (H, J) ndarray</span>
  236. <span class="sd"> Binary region image with filled holes which has the same size as</span>
  237. <span class="sd"> bounding box.</span>
  238. <span class="sd"> **image** : (H, J) ndarray</span>
  239. <span class="sd"> Sliced binary region image which has the same size as bounding box.</span>
  240. <span class="sd"> **inertia_tensor** : (2, 2) ndarray</span>
  241. <span class="sd"> Inertia tensor of the region for the rotation around its mass.</span>
  242. <span class="sd"> **inertia_tensor_eigvals** : tuple</span>
  243. <span class="sd"> The two eigen values of the inertia tensor in decreasing order.</span>
  244. <span class="sd"> **intensity_image** : ndarray</span>
  245. <span class="sd"> Image inside region bounding box.</span>
  246. <span class="sd"> **label** : int</span>
  247. <span class="sd"> The label in the labeled input image.</span>
  248. <span class="sd"> **local_centroid** : array</span>
  249. <span class="sd"> Centroid coordinate tuple ``(row, col)``, relative to region bounding</span>
  250. <span class="sd"> box.</span>
  251. <span class="sd"> **major_axis_length** : float</span>
  252. <span class="sd"> The length of the major axis of the ellipse that has the same</span>
  253. <span class="sd"> normalized second central moments as the region.</span>
  254. <span class="sd"> **max_intensity** : float</span>
  255. <span class="sd"> Value with the greatest intensity in the region.</span>
  256. <span class="sd"> **mean_intensity** : float</span>
  257. <span class="sd"> Value with the mean intensity in the region.</span>
  258. <span class="sd"> **min_intensity** : float</span>
  259. <span class="sd"> Value with the least intensity in the region.</span>
  260. <span class="sd"> **minor_axis_length** : float</span>
  261. <span class="sd"> The length of the minor axis of the ellipse that has the same</span>
  262. <span class="sd"> normalized second central moments as the region.</span>
  263. <span class="sd"> **moments** : (3, 3) ndarray</span>
  264. <span class="sd"> Spatial moments up to 3rd order::</span>
  265. <span class="sd"> m_ji = sum{ array(x, y) * x^j * y^i }</span>
  266. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region.</span>
  267. <span class="sd"> **moments_central** : (3, 3) ndarray</span>
  268. <span class="sd"> Central moments (translation invariant) up to 3rd order::</span>
  269. <span class="sd"> mu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }</span>
  270. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region,</span>
  271. <span class="sd"> and `x_c` and `y_c` are the coordinates of the region&#39;s centroid.</span>
  272. <span class="sd"> **moments_hu** : tuple</span>
  273. <span class="sd"> Hu moments (translation, scale and rotation invariant).</span>
  274. <span class="sd"> **moments_normalized** : (3, 3) ndarray</span>
  275. <span class="sd"> Normalized moments (translation and scale invariant) up to 3rd order::</span>
  276. <span class="sd"> nu_ji = mu_ji / m_00^[(i+j)/2 + 1]</span>
  277. <span class="sd"> where `m_00` is the zeroth spatial moment.</span>
  278. <span class="sd"> **orientation** : float</span>
  279. <span class="sd"> Angle between the X-axis and the major axis of the ellipse that has</span>
  280. <span class="sd"> the same second-moments as the region. Ranging from `-pi/2` to</span>
  281. <span class="sd"> `pi/2` in counter-clockwise direction.</span>
  282. <span class="sd"> **perimeter** : float</span>
  283. <span class="sd"> Perimeter of object which approximates the contour as a line</span>
  284. <span class="sd"> through the centers of border pixels using a 4-connectivity.</span>
  285. <span class="sd"> **solidity** : float</span>
  286. <span class="sd"> Ratio of pixels in the region to pixels of the convex hull image.</span>
  287. <span class="sd"> **weighted_centroid** : array</span>
  288. <span class="sd"> Centroid coordinate tuple ``(row, col)`` weighted with intensity</span>
  289. <span class="sd"> image.</span>
  290. <span class="sd"> **weighted_local_centroid** : array</span>
  291. <span class="sd"> Centroid coordinate tuple ``(row, col)``, relative to region bounding</span>
  292. <span class="sd"> box, weighted with intensity image.</span>
  293. <span class="sd"> **weighted_moments** : (3, 3) ndarray</span>
  294. <span class="sd"> Spatial moments of intensity image up to 3rd order::</span>
  295. <span class="sd"> wm_ji = sum{ array(x, y) * x^j * y^i }</span>
  296. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region.</span>
  297. <span class="sd"> **weighted_moments_central** : (3, 3) ndarray</span>
  298. <span class="sd"> Central moments (translation invariant) of intensity image up to</span>
  299. <span class="sd"> 3rd order::</span>
  300. <span class="sd"> wmu_ji = sum{ array(x, y) * (x - x_c)^j * (y - y_c)^i }</span>
  301. <span class="sd"> where the sum is over the `x`, `y` coordinates of the region,</span>
  302. <span class="sd"> and `x_c` and `y_c` are the coordinates of the region&#39;s weighted</span>
  303. <span class="sd"> centroid.</span>
  304. <span class="sd"> **weighted_moments_hu** : tuple</span>
  305. <span class="sd"> Hu moments (translation, scale and rotation invariant) of intensity</span>
  306. <span class="sd"> image.</span>
  307. <span class="sd"> **weighted_moments_normalized** : (3, 3) ndarray</span>
  308. <span class="sd"> Normalized moments (translation and scale invariant) of intensity</span>
  309. <span class="sd"> image up to 3rd order::</span>
  310. <span class="sd"> wnu_ji = wmu_ji / wm_00^[(i+j)/2 + 1]</span>
  311. <span class="sd"> where ``wm_00`` is the zeroth spatial moment (intensity-weighted area).</span>
  312. <span class="sd"> .. [1] http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops</span>
  313. <span class="sd"> &quot;&quot;&quot;</span>
  314. <span class="k">try</span><span class="p">:</span>
  315. <span class="n">vals</span> <span class="o">=</span> <span class="p">[]</span>
  316. <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">__regionsprops</span><span class="p">:</span>
  317. <span class="n">vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">prop_name</span><span class="p">))</span>
  318. <span class="k">return</span> <span class="n">vals</span>
  319. <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  320. <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>
  321. <span class="k">return</span> <span class="kc">None</span></div></div>
  322. </pre></div>
  323. </div>
  324. </div>
  325. </div>
  326. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  327. <div class="sphinxsidebarwrapper">
  328. <h1 class="logo"><a href="../index.html">Image Features Extraction</a></h1>
  329. <h3>Navigation</h3>
  330. <ul>
  331. <li class="toctree-l1"><a class="reference internal" href="../tutorial.html">Tutorial</a></li>
  332. <li class="toctree-l1"><a class="reference internal" href="../code.html">Classes/Modules</a></li>
  333. </ul>
  334. <div class="relations">
  335. <h3>Related Topics</h3>
  336. <ul>
  337. <li><a href="../index.html">Documentation overview</a><ul>
  338. <li><a href="index.html">Module code</a><ul>
  339. </ul></li>
  340. </ul></li>
  341. </ul>
  342. </div>
  343. <div id="searchbox" style="display: none" role="search">
  344. <h3>Quick search</h3>
  345. <form class="search" action="../search.html" method="get">
  346. <div><input type="text" name="q" /></div>
  347. <div><input type="submit" value="Go" /></div>
  348. <input type="hidden" name="check_keywords" value="yes" />
  349. <input type="hidden" name="area" value="default" />
  350. </form>
  351. </div>
  352. <script type="text/javascript">$('#searchbox').show(0);</script>
  353. </div>
  354. </div>
  355. <div class="clearer"></div>
  356. </div>
  357. <div class="footer">
  358. &copy;2017, Remigio Picone.
  359. |
  360. Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.3</a>
  361. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
  362. </div>
  363. </body>
  364. </html>