Skip to content

Commit

Permalink
update sphinx docs with hash plot
Browse files Browse the repository at this point in the history
  • Loading branch information
erdogant committed Apr 22, 2022
1 parent f9ab63d commit 21393d2
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 38 deletions.
Binary file added docs/figs/imghash01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/pages/doctrees/Abstract.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/Coding quality.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/Documentation.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/Examples.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/Installation.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/core_functions.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/pages/doctrees/hash_functions.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/pages/doctrees/undouble.undouble.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/pages/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 662ee8584ae1a50c8ab39426a033c914
config: a6e5e24022e8933cefb7c61cda6c8876
tags: 645f666f9bcd5a90fca523b33c5a78b7
1 change: 1 addition & 0 deletions docs/pages/html/Abstract.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#compute-blur">compute_blur</a></li>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Coding quality.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#compute-blur">compute_blur</a></li>
Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#compute-blur">compute_blur</a></li>
Expand Down
13 changes: 13 additions & 0 deletions docs/pages/html/Examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#compute-blur">compute_blur</a></li>
Expand Down Expand Up @@ -212,6 +213,18 @@ <h2>Move files<a class="headerlink" href="#move-files" title="Permalink to this
<section id="plot-image-hash">
<h2>Plot image hash<a class="headerlink" href="#plot-image-hash" title="Permalink to this headline"></a></h2>
<p>To plot the image hashes of the flowers we need to return the dict (see parameter). I will plot the hash of 1 flower image but the hashes can be plotted for all images.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span> <span class="c1"># plot the image-hash for some specified indexes:</span>
<span class="c1"># The index is based on the ordering in the results:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">results</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="c1"># Make the plot for the first index</span>
<span class="n">model</span><span class="o">.</span><span class="n">plot_hash</span><span class="p">(</span><span class="n">idx</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>

<span class="c1"># Make the plot for a specific filenames</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">results</span><span class="p">[</span><span class="s1">&#39;filenames&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
<span class="n">model</span><span class="o">.</span><span class="n">plot_hash</span><span class="p">(</span><span class="n">filenames</span><span class="o">=</span><span class="n">filenames</span><span class="p">)</span>
</pre></div>
</div>
<p># Doing the same only manually:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Compute image-hash</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">compute_hash</span><span class="p">(</span><span class="n">return_dict</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

Expand Down
1 change: 1 addition & 0 deletions docs/pages/html/Installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#compute-blur">compute_blur</a></li>
Expand Down
Binary file added docs/pages/html/_images/imghash01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/pages/html/_sources/Examples.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ Plot image hash

To plot the image hashes of the flowers we need to return the dict (see parameter). I will plot the hash of 1 flower image but the hashes can be plotted for all images.

.. code:: python
# plot the image-hash for some specified indexes:
# The index is based on the ordering in the results:
print(model.results.keys())
# Make the plot for the first index
model.plot_hash(idx=[0])
# Make the plot for a specific filenames
filenames = model.results['filenames'][0:2]
model.plot_hash(filenames=filenames)
# Doing the same only manually:

.. code:: python
# Compute image-hash
Expand Down
43 changes: 42 additions & 1 deletion docs/pages/html/_sources/core_functions.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ The following core functionalities allows to group images on image-hash, and sys
.import_data()
.compute_hash()
.group()
.move()
.plot()
.plot_hash()
.move()
Input data
Expand Down Expand Up @@ -219,6 +220,46 @@ Plot all images that could be combined into a group with identical image-hash or
The function can be found here: :func:`undouble.undouble.Undouble.plot`


Plot hash
************

This functionality is practical if you need to investigate the grouping of images based on the hashes that are generated: :func:`undouble.undouble.Undouble.plot_hash`

.. code:: python
# Import library
from undouble import Undouble
# Init with default settings
model = Undouble()
# Import example data
# targetdir = model.import_example(data='flowers')
# Importing the files files from disk, cleaning and pre-processing
model.import_data(r'./undouble/data/flower_images/')
# Compute image-hash
model.compute_hash(method='phash', hash_size=6)
# Plot the image-hash for a set of indexes
model.plot_hash(idx=[0, 1])
# Plot the image-hash for a set of filenames
filenames = model.results['filenames'][0:2]
filenames = ['0001.png', '0002.png']
model.plot_hash(filenames=filenames)
.. |imghash01| image:: ../figs/imghash01.png
.. table:: Plot image hash
:align: center

+------------------+
| |imghash01| |
+------------------+


Preprocessing
###############

Expand Down
72 changes: 52 additions & 20 deletions docs/pages/html/_static/doctools.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ var Documentation = {
this.fixFirefoxAnchorBug();
this.highlightSearchWords();
this.initIndexTable();
if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) {
this.initOnKeyListeners();
}
this.initOnKeyListeners();
},

/**
Expand Down Expand Up @@ -269,6 +267,13 @@ var Documentation = {
window.history.replaceState({}, '', url);
},

/**
* helper function to focus on search bar
*/
focusSearchBar : function() {
$('input[name=q]').first().focus();
},

/**
* make the url absolute
*/
Expand All @@ -291,27 +296,54 @@ var Documentation = {
},

initOnKeyListeners: function() {
// only install a listener if it is really needed
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
return;

$(document).keydown(function(event) {
var activeElementType = document.activeElement.tagName;
// don't navigate when in search box, textarea, dropdown or button
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
&& activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
&& !event.shiftKey) {
switch (event.keyCode) {
case 37: // left
var prevHref = $('link[rel="prev"]').prop('href');
if (prevHref) {
window.location.href = prevHref;
return false;
}
break;
case 39: // right
var nextHref = $('link[rel="next"]').prop('href');
if (nextHref) {
window.location.href = nextHref;
return false;
}
break;
&& activeElementType !== 'BUTTON') {
if (event.altKey || event.ctrlKey || event.metaKey)
return;

if (!event.shiftKey) {
switch (event.key) {
case 'ArrowLeft':
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
break;
var prevHref = $('link[rel="prev"]').prop('href');
if (prevHref) {
window.location.href = prevHref;
return false;
}
break;
case 'ArrowRight':
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
break;
var nextHref = $('link[rel="next"]').prop('href');
if (nextHref) {
window.location.href = nextHref;
return false;
}
break;
case 'Escape':
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
break;
Documentation.hideSearchWords();
return false;
}
}

// some keyboard layouts may need Shift to get /
switch (event.key) {
case '/':
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
break;
Documentation.focusSearchBar();
return false;
}
}
});
Expand Down
4 changes: 3 additions & 1 deletion docs/pages/html/_static/documentation_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ var DOCUMENTATION_OPTIONS = {
LINK_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt',
NAVIGATION_WITH_KEYS: false
NAVIGATION_WITH_KEYS: false,
SHOW_SEARCH_SUMMARY: true,
ENABLE_SEARCH_SHORTCUTS: true,
};
8 changes: 2 additions & 6 deletions docs/pages/html/_static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ var Search = {
}
// stem the word
var word = stemmer.stemWord(tmp[i].toLowerCase());
// prevent stemmer from cutting word smaller than two chars
if(word.length < 3 && tmp[i].length >= 3) {
word = tmp[i];
}
var toAppend;
// select the correct list
if (word[0] == '-') {
Expand Down Expand Up @@ -276,7 +272,7 @@ var Search = {
setTimeout(function() {
displayNextItem();
}, 5);
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
} else if (DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY) {
$.ajax({url: requestUrl,
dataType: "text",
complete: function(jqxhr, textstatus) {
Expand All @@ -293,7 +289,7 @@ var Search = {
}, 5);
}});
} else {
// no source available, just display title
// just display title
Search.output.append(listItem);
setTimeout(function() {
displayNextItem();
Expand Down
42 changes: 41 additions & 1 deletion docs/pages/html/core_functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<li class="toctree-l1"><a class="reference internal" href="#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="#compute-blur">compute_blur</a></li>
Expand Down Expand Up @@ -127,8 +128,9 @@ <h1>Core functionalities<a class="headerlink" href="#core-functionalities" title
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="o">.</span><span class="n">import_data</span><span class="p">()</span>
<span class="o">.</span><span class="n">compute_hash</span><span class="p">()</span>
<span class="o">.</span><span class="n">group</span><span class="p">()</span>
<span class="o">.</span><span class="n">move</span><span class="p">()</span>
<span class="o">.</span><span class="n">plot</span><span class="p">()</span>
<span class="o">.</span><span class="n">plot_hash</span><span class="p">()</span>
<span class="o">.</span><span class="n">move</span><span class="p">()</span>
</pre></div>
</div>
</section>
Expand Down Expand Up @@ -311,6 +313,44 @@ <h1>Moving images<a class="headerlink" href="#moving-images" title="Permalink to
<h1>Plot<a class="headerlink" href="#plot" title="Permalink to this headline"></a></h1>
<p>Plot all images that could be combined into a group with identical image-hash or &lt;= threshold.
The function can be found here: <a class="reference internal" href="undouble.undouble.html#undouble.undouble.Undouble.plot" title="undouble.undouble.Undouble.plot"><code class="xref py py-func docutils literal notranslate"><span class="pre">undouble.undouble.Undouble.plot()</span></code></a></p>
</section>
<section id="plot-hash">
<h1>Plot hash<a class="headerlink" href="#plot-hash" title="Permalink to this headline"></a></h1>
<p>This functionality is practical if you need to investigate the grouping of images based on the hashes that are generated: <a class="reference internal" href="undouble.undouble.html#undouble.undouble.Undouble.plot_hash" title="undouble.undouble.Undouble.plot_hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">undouble.undouble.Undouble.plot_hash()</span></code></a></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Import library</span>
<span class="kn">from</span> <span class="nn">undouble</span> <span class="kn">import</span> <span class="n">Undouble</span>

<span class="c1"># Init with default settings</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">Undouble</span><span class="p">()</span>

<span class="c1"># Import example data</span>
<span class="c1"># targetdir = model.import_example(data=&#39;flowers&#39;)</span>

<span class="c1"># Importing the files files from disk, cleaning and pre-processing</span>
<span class="n">model</span><span class="o">.</span><span class="n">import_data</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;./undouble/data/flower_images/&#39;</span><span class="p">)</span>

<span class="c1"># Compute image-hash</span>
<span class="n">model</span><span class="o">.</span><span class="n">compute_hash</span><span class="p">(</span><span class="n">method</span><span class="o">=</span><span class="s1">&#39;phash&#39;</span><span class="p">,</span> <span class="n">hash_size</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>

<span class="c1"># Plot the image-hash for a set of indexes</span>
<span class="n">model</span><span class="o">.</span><span class="n">plot_hash</span><span class="p">(</span><span class="n">idx</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>

<span class="c1"># Plot the image-hash for a set of filenames</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">results</span><span class="p">[</span><span class="s1">&#39;filenames&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span>
<span class="n">filenames</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;0001.png&#39;</span><span class="p">,</span> <span class="s1">&#39;0002.png&#39;</span><span class="p">]</span>
<span class="n">model</span><span class="o">.</span><span class="n">plot_hash</span><span class="p">(</span><span class="n">filenames</span><span class="o">=</span><span class="n">filenames</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils align-center" id="id1">
<caption><span class="caption-text">Plot image hash</span><a class="headerlink" href="#id1" title="Permalink to this table"></a></caption>
<colgroup>
<col style="width: 100%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><img alt="imghash01" src="_images/imghash01.png" /></p></td>
</tr>
</tbody>
</table>
<p>Before we can determine the image-hash from an image, we need to decolorize the image, normalize the pixel values, and scale the image.
The reasoning for decolorizing is that most information we need to “recognize” an image is readily present in the grayscale channel.
In addition, the reduction from 24 bits per pixel for RGB to 8 bits per pixel is computationally more attractive; time-wise and memory-wise.
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#grouping-images">Grouping images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#moving-images">Moving images</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot">Plot</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#plot-hash">Plot hash</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#scaling">scaling</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#resizing">Resizing</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_functions.html#compute-blur">compute_blur</a></li>
Expand Down Expand Up @@ -227,6 +228,10 @@ <h2 id="P">P</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="undouble.undouble.html#undouble.undouble.Undouble.plot">plot() (undouble.undouble.Undouble method)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="undouble.undouble.html#undouble.undouble.Undouble.plot_hash">plot_hash() (undouble.undouble.Undouble method)</a>
</li>
</ul></td>
</tr></table>
Expand Down
Loading

0 comments on commit 21393d2

Please sign in to comment.