Image.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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">scipy.misc</span> <span class="k">as</span> <span class="nn">sm</span>
  35. <span class="kn">from</span> <span class="nn">skimage.measure</span> <span class="k">import</span> <span class="n">label</span>
  36. <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>
  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">image_features_extraction</span> <span class="k">import</span> <span class="n">Regions</span>
  39. <span class="kn">from</span> <span class="nn">image_features_extraction</span> <span class="k">import</span> <span class="n">MyException</span>
  40. <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>
  41. <span class="sd">&quot;&quot;&quot;</span>
  42. <span class="sd"> Class image containing the single image obtained from the collection :class:`Images`</span>
  43. <span class="sd"> :example:</span>
  44. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  45. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  46. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  47. <span class="sd"> &quot;&quot;&quot;</span>
  48. <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>
  49. <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>
  50. <span class="bp">self</span><span class="o">.</span><span class="n">__regions</span> <span class="o">=</span> <span class="kc">None</span>
  51. <span class="bp">self</span><span class="o">.</span><span class="n">__mask</span> <span class="o">=</span> <span class="kc">None</span>
  52. <span class="k">try</span><span class="p">:</span>
  53. <span class="bp">self</span><span class="o">.</span><span class="n">__get_regions</span><span class="p">()</span>
  54. <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>
  55. <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>
  56. <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>
  57. <span class="sd">&quot;&quot;&quot;</span>
  58. <span class="sd"> file_name(...) return the full file name of the image</span>
  59. <span class="sd"> &quot;&quot;&quot;</span>
  60. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__full_file_name</span></div>
  61. <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>
  62. <span class="sd">&quot;&quot;&quot;</span>
  63. <span class="sd"> regions(...) returns the Object Regions</span>
  64. <span class="sd"> &gt;&gt;&gt; import image_features_extraction as fe</span>
  65. <span class="sd"> &gt;&gt;&gt; imgs = fe.Images(folder_name)</span>
  66. <span class="sd"> &gt;&gt;&gt; img = imgs.item(1)</span>
  67. <span class="sd"> &gt;&gt;&gt; regs = img.Regions()</span>
  68. <span class="sd"> &quot;&quot;&quot;</span>
  69. <span class="k">try</span><span class="p">:</span>
  70. <span class="n">regs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_regions</span><span class="p">()</span>
  71. <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="n">regs</span><span class="p">)</span>
  72. <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>
  73. <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>
  74. <span class="k">return</span> <span class="kc">None</span></div>
  75. <span class="k">def</span> <span class="nf">__get_regions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  76. <span class="c1"># load the image</span>
  77. <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">file_name</span><span class="p">())</span>
  78. <span class="c1"># ithresholding to build the map</span>
  79. <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>
  80. <span class="c1"># cretes the mask</span>
  81. <span class="bp">self</span><span class="o">.</span><span class="n">__mask</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>
  82. <span class="c1"># returns the single segmented elements of the image</span>
  83. <span class="n">labels_segment</span> <span class="o">=</span> <span class="n">label</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__mask</span><span class="p">)</span>
  84. <span class="c1"># removes the image elements at the border</span>
  85. <span class="bp">self</span><span class="o">.</span><span class="n">__regions</span> <span class="o">=</span> <span class="n">clear_border</span><span class="p">(</span><span class="n">labels_segment</span><span class="p">)</span>
  86. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__regions</span></div>
  87. </pre></div>
  88. </div>
  89. </div>
  90. </div>
  91. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  92. <div class="sphinxsidebarwrapper">
  93. <h1 class="logo"><a href="../index.html">image features extraction</a></h1>
  94. <h3>Navigation</h3>
  95. <p class="caption"><span class="caption-text">Contents:</span></p>
  96. <ul>
  97. <li class="toctree-l1"><a class="reference internal" href="../intro.html">Introduction</a></li>
  98. <li class="toctree-l1"><a class="reference internal" href="../tutorial.html">Tutorial</a></li>
  99. <li class="toctree-l1"><a class="reference internal" href="../code.html">Classes/Modules</a></li>
  100. </ul>
  101. <div class="relations">
  102. <h3>Related Topics</h3>
  103. <ul>
  104. <li><a href="../index.html">Documentation overview</a><ul>
  105. <li><a href="index.html">Module code</a><ul>
  106. </ul></li>
  107. </ul></li>
  108. </ul>
  109. </div>
  110. <div id="searchbox" style="display: none" role="search">
  111. <h3>Quick search</h3>
  112. <form class="search" action="../search.html" method="get">
  113. <div><input type="text" name="q" /></div>
  114. <div><input type="submit" value="Go" /></div>
  115. <input type="hidden" name="check_keywords" value="yes" />
  116. <input type="hidden" name="area" value="default" />
  117. </form>
  118. </div>
  119. <script type="text/javascript">$('#searchbox').show(0);</script>
  120. </div>
  121. </div>
  122. <div class="clearer"></div>
  123. </div>
  124. <div class="footer">
  125. &copy;2017, Remigio Picone.
  126. |
  127. Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.3</a>
  128. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
  129. </div>
  130. </body>
  131. </html>