-
Notifications
You must be signed in to change notification settings - Fork 1
/
alpha.html
83 lines (83 loc) · 42.1 KB
/
alpha.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>Alpha Estimation — PyMatting 1.1.10 documentation</title><link rel="stylesheet" href="/katex.min.css"><link rel="stylesheet" href="/style.css"><script src="/katex.min.js"></script></head><body><div class="sidebar"><div class="logo"><a href="/" class="sidebarlink"><img src="/figures/lemur_small.png" width="50px"></a><a href="/" class="logotext">PyMatting</a></div><div class="sidebarcontents">CONTENTS</div><ul><li><a href="/index.html" class="sidebarlink">PyMatting</a></li><li class="sidebarlink"><a href="/api.html" class="sidebarlink">API Reference</a><br><ul><li><a href="/alpha.html" class="sidebarlink currentpage">Alpha Estimation</a></li><li><a href="/cutout.html" class="sidebarlink">Cutout Function</a></li><li><a href="/foreground.html" class="sidebarlink">Foreground Estimation</a></li><li><a href="/laplacian.html" class="sidebarlink">Matting Laplacians</a></li><li><a href="/preconditioner.html" class="sidebarlink">Preconditioners</a></li><li><a href="/solver.html" class="sidebarlink">Solvers</a></li><li><a href="/util.html" class="sidebarlink">Utility Functions</a></li></ul></li><li><a href="/examples.html" class="sidebarlink">Examples</a></li><li><a href="/benchmarks.html" class="sidebarlink">Benchmarks</a></li><li><a href="/references.html" class="sidebarlink">Biblography</a></li><li><a href="https://pypi.org/project/PyMatting/" class="sidebarlink">PyPI</a></li><li><a href="https://www.github.com/pymatting/pymatting" class="sidebarlink">GitHub</a></li></ul></div><div class="middle"><h1>Alpha Estimation</h1><div><div class="function"><div id="estimate_alpha_cf"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/alpha/estimate_alpha_cf.py#L8-L78"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.estimate_alpha_cf</h3><a href="#estimate_alpha_cf" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>estimate_alpha_cf</span><span class=operator>(</span><span class=space>
</span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=name>preconditioner</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Estimate alpha from an input image and an input trimap using Closed-Form Alpha Matting as proposed by </span><span class="citation"><a href="/references.html#LLW07">[LLW07]</a></span><span class="text">.</span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">image</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Image with shape </span><span class="inline_math">\(h \times w \times d\)</span><span class="text"> for which the alpha matte should be estimated</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Trimap with shape </span><span class="inline_math">\(h \times w\)</span><span class="text"> of the image</span></div></ul></li><li class="parameteritem"><span class="parameter">preconditioner</span> (<i>function or scipy.sparse.linalg.LinearOperator</i>)<ul><div class="parameterdescription"><span class="text">Function or sparse matrix that applies the preconditioner to a vector (default: ichol)</span></div></ul></li><li class="parameteritem"><span class="parameter">laplacian_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>cf_laplacian</span></span></span><span class="text"> function</span></div></ul></li><li class="parameteritem"><span class="parameter">cg_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>cg</span></span></span><span class="text"> solver</span></div></ul></li><li class="parameteritem"><span class="parameter">is_known</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Binary mask of pixels for which to compute the laplacian matrix. </span><span class="text">Providing this parameter might improve performance if few pixels are unknown.</span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">alpha</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated alpha matte</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>image</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"RGB"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>trimap</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur_trimap.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"GRAY"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>alpha</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>estimate_alpha_cf</span><span class=operator>(</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"epsilon"</span><span class=operator>:</span><span class=space> </span><span class=number>1e-6</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"maxiter"</span><span class=operator>:</span><span class=number>2000</span><span class=operator>}</span><span class=operator>)</span></div></div></div></div></div><div><div class="function"><div id="estimate_alpha_knn"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/alpha/estimate_alpha_knn.py#L9-L56"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.estimate_alpha_knn</h3><a href="#estimate_alpha_knn" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>estimate_alpha_knn</span><span class=operator>(</span><span class=space>
</span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=name>preconditioner</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Estimate alpha from an input image and an input trimap using KNN Matting similar to </span><span class="citation"><a href="/references.html#CLT13">[CLT13]</a></span><span class="text">.
See </span><span class="inline_code"><span class="codeinline"><span class=name>knn_laplacian</span></span></span><span class="text"> for more details.</span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">image</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Image with shape </span><span class="inline_math">\(h \times w \times d\)</span><span class="text"> for which the alpha matte should be estimated</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Trimap with shape </span><span class="inline_math">\(h \times w\)</span><span class="text"> of the image</span></div></ul></li><li class="parameteritem"><span class="parameter">preconditioner</span> (<i>function or scipy.sparse.linalg.LinearOperator</i>)<ul><div class="parameterdescription"><span class="text">Function or sparse matrix that applies the preconditioner to a vector (default: jacobi)</span></div></ul></li><li class="parameteritem"><span class="parameter">laplacian_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>knn_laplacian</span></span></span><span class="text"> function</span></div></ul></li><li class="parameteritem"><span class="parameter">cg_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>cg</span></span></span><span class="text"> solver</span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">alpha</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated alpha matte</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>image</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"RGB"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>trimap</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur_trimap.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"GRAY"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>alpha</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>estimate_alpha_knn</span><span class=operator>(</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"n_neighbors"</span><span class=operator>:</span><span class=space> </span><span class=operator>[</span><span class=number>15</span><span class=operator>,</span><span class=space> </span><span class=number>10</span><span class=operator>]</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"maxiter"</span><span class=operator>:</span><span class=number>2000</span><span class=operator>}</span><span class=operator>)</span></div></div></div></div></div><div><div class="function"><div id="estimate_alpha_lbdm"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/alpha/estimate_alpha_lbdm.py#L9-L56"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.estimate_alpha_lbdm</h3><a href="#estimate_alpha_lbdm" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>estimate_alpha_lbdm</span><span class=operator>(</span><span class=space>
</span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=name>preconditioner</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Estimate alpha from an input image and an input trimap using Learning Based Digital Matting as proposed by </span><span class="citation"><a href="/references.html#ZK09">[ZK09]</a></span><span class="text">.</span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">image</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Image with shape </span><span class="inline_math">\(h \times w \times d\)</span><span class="text"> for which the alpha matte should be estimated</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Trimap with shape </span><span class="inline_math">\(h \times w\)</span><span class="text"> of the image</span></div></ul></li><li class="parameteritem"><span class="parameter">preconditioner</span> (<i>function or scipy.sparse.linalg.LinearOperator</i>)<ul><div class="parameterdescription"><span class="text">Function or sparse matrix that applies the preconditioner to a vector (default: ichol)</span></div></ul></li><li class="parameteritem"><span class="parameter">laplacian_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>lbdm_laplacian</span></span></span><span class="text"> function</span></div></ul></li><li class="parameteritem"><span class="parameter">cg_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>cg</span></span></span><span class="text"> solver</span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">alpha</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated alpha matte</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>image</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"RGB"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>trimap</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur_trimap.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"GRAY"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>alpha</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>estimate_alpha_lbdm</span><span class=operator>(</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"epsilon"</span><span class=operator>:</span><span class=space> </span><span class=number>1e-6</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"maxiter"</span><span class=operator>:</span><span class=number>2000</span><span class=operator>}</span><span class=operator>)</span></div></div></div></div></div><div><div class="function"><div id="estimate_alpha_lkm"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/alpha/estimate_alpha_lkm.py#L8-L64"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.estimate_alpha_lkm</h3><a href="#estimate_alpha_lkm" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>estimate_alpha_lkm</span><span class=operator>(</span><span class=space>
</span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Estimate alpha from an input image and an input trimap as described in Fast Matting Using Large Kernel Matting Laplacian Matrices by </span><span class="citation"><a href="/references.html#HST10">[HST10]</a></span><span class="text">.</span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">image</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Image with shape </span><span class="inline_math">\(h \times w \times d\)</span><span class="text"> for which the alpha matte should be estimated</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Trimap with shape </span><span class="inline_math">\(h \times w\)</span><span class="text"> of the image</span></div></ul></li><li class="parameteritem"><span class="parameter">laplacian_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>lkm_laplacian</span></span></span><span class="text"> function</span></div></ul></li><li class="parameteritem"><span class="parameter">cg_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>cg</span></span></span><span class="text"> solver</span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">alpha</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated alpha matte</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>image</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"RGB"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>trimap</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur_trimap.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"GRAY"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>alpha</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>estimate_alpha_lkm</span><span class=operator>(</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"epsilon"</span><span class=operator>:</span><span class=space> </span><span class=number>1e-6</span><span class=operator>,</span><span class=space> </span><span class=string>"radius"</span><span class=operator>:</span><span class=space> </span><span class=number>15</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"maxiter"</span><span class=operator>:</span><span class=number>2000</span><span class=operator>}</span><span class=operator>)</span></div></div></div></div></div><div><div class="function"><div id="estimate_alpha_rw"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/alpha/estimate_alpha_rw.py#L9-L56"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.estimate_alpha_rw</h3><a href="#estimate_alpha_rw" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>estimate_alpha_rw</span><span class=operator>(</span><span class=space>
</span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=name>preconditioner</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=operator>}</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Estimate alpha from an input image and an input trimap using Learning Based Digital Matting as proposed by </span><span class="citation"><a href="/references.html#GSAW05">[GSAW05]</a></span><span class="text">.</span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">image</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Image with shape </span><span class="inline_math">\(h \times w \times d\)</span><span class="text"> for which the alpha matte should be estimated</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Trimap with shape </span><span class="inline_math">\(h \times w\)</span><span class="text"> of the image</span></div></ul></li><li class="parameteritem"><span class="parameter">preconditioner</span> (<i>function or scipy.sparse.linalg.LinearOperator</i>)<ul><div class="parameterdescription"><span class="text">Function or sparse matrix that applies the preconditioner to a vector (default: jacobi)</span></div></ul></li><li class="parameteritem"><span class="parameter">laplacian_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>rw_laplacian</span></span></span><span class="text"> function</span></div></ul></li><li class="parameteritem"><span class="parameter">cg_kwargs</span> (<i>dictionary</i>)<ul><div class="parameterdescription"><span class="text">Arguments passed to the </span><span class="inline_code"><span class="codeinline"><span class=name>cg</span></span></span><span class="text"> solver</span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">alpha</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated alpha matte</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>image</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"RGB"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>trimap</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur_trimap.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"GRAY"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>alpha</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>estimate_alpha_rw</span><span class=operator>(</span><span class=space>
</span><span class=operator>.</span><span class=operator>.</span><span class=operator>.</span><span class=operator>.</span><span class=space> </span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>laplacian_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"sigma"</span><span class=operator>:</span><span class=space> </span><span class=number>0.03</span><span class=operator>}</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>cg_kwargs</span><span class=operator>=</span><span class=operator>{</span><span class=string>"maxiter"</span><span class=operator>:</span><span class=number>2000</span><span class=operator>}</span><span class=operator>)</span></div></div></div></div></div><div><div class="function"><div id="estimate_alpha_sm"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/alpha/estimate_alpha_sm.py#L4-L165"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.estimate_alpha_sm</h3><a href="#estimate_alpha_sm" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>estimate_alpha_sm</span><span class=operator>(</span><span class=space>
</span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=name>return_foreground_background</span><span class=operator>=</span><span class=keyword>False</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap_expansion_radius</span><span class=operator>=</span><span class=number>10</span><span class=operator>,</span><span class=space>
</span><span class=name>trimap_expansion_threshold</span><span class=operator>=</span><span class=number>0.02</span><span class=operator>,</span><span class=space>
</span><span class=name>sample_gathering_angles</span><span class=operator>=</span><span class=number>4</span><span class=operator>,</span><span class=space>
</span><span class=name>sample_gathering_weights</span><span class=operator>=</span><span class=operator>(</span><span class=number>3.0</span><span class=operator>,</span><span class=space> </span><span class=number>2.0</span><span class=operator>,</span><span class=space> </span><span class=number>1.0</span><span class=operator>,</span><span class=space> </span><span class=number>4.0</span><span class=operator>)</span><span class=operator>,</span><span class=space>
</span><span class=name>sample_gathering_Np_radius</span><span class=operator>=</span><span class=number>1</span><span class=operator>,</span><span class=space>
</span><span class=name>sample_refinement_radius</span><span class=operator>=</span><span class=number>5</span><span class=operator>,</span><span class=space>
</span><span class=name>local_smoothing_radius1</span><span class=operator>=</span><span class=number>5</span><span class=operator>,</span><span class=space>
</span><span class=name>local_smoothing_radius2</span><span class=operator>=</span><span class=number>5</span><span class=operator>,</span><span class=space>
</span><span class=name>local_smoothing_radius3</span><span class=operator>=</span><span class=number>5</span><span class=operator>,</span><span class=space>
</span><span class=name>local_smoothing_sigma_sq1</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>local_smoothing_sigma_sq2</span><span class=operator>=</span><span class=number>0.1</span><span class=operator>,</span><span class=space>
</span><span class=name>local_smoothing_sigma_sq3</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Estimate alpha from an input image and an input trimap using Shared Matting as proposed by </span><span class="citation"><a href="/references.html#GO10">[GO10]</a></span><span class="text">.</span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">image</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Image with shape </span><span class="inline_math">\(h \times w \times d\)</span><span class="text"> for which the alpha matte should be estimated</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Trimap with shape </span><span class="inline_math">\(h \times w\)</span><span class="text"> of the image</span></div></ul></li><li class="parameteritem"><span class="parameter">return_foreground_background</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Whether to return foreground and background estimate. They will be computed either way</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap_expansion_radius</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">How much to expand trimap.</span></div></ul></li><li class="parameteritem"><span class="parameter">trimap_expansion_threshold</span> (<i>float</i>)<ul><div class="parameterdescription"><span class="text">Which pixel colors are similar enough to expand trimap into</span></div></ul></li><li class="parameteritem"><span class="parameter">sample_gathering_angles</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">In how many directions to search for new samples.</span></div></ul></li><li class="parameteritem"><span class="parameter">sample_gathering_weights</span> (<i>Tuple[float, float, float, float]</i>)<ul><div class="parameterdescription"><span class="text">Weights for various cost functions</span></div></ul></li><li class="parameteritem"><span class="parameter">sample_gathering_Np_radius</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">Radius of Np function</span></div></ul></li><li class="parameteritem"><span class="parameter">sample_refinement_radius</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">Search region for better neighboring samples</span></div></ul></li><li class="parameteritem"><span class="parameter">local_smoothing_radius1</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">Radius for foreground/background smoothing</span></div></ul></li><li class="parameteritem"><span class="parameter">local_smoothing_radius2</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">Radius for confidence computation</span></div></ul></li><li class="parameteritem"><span class="parameter">local_smoothing_radius3</span> (<i>int</i>)<ul><div class="parameterdescription"><span class="text">Radius for low frequency alpha computation</span></div></ul></li><li class="parameteritem"><span class="parameter">local_smoothing_sigma_sq1</span> (<i>float</i>)<ul><div class="parameterdescription"><span class="text">Squared sigma value for foreground/background smoothing </span><span class="text">Defaults to </span><span class="inline_code"><span class="codeinline"><span class=operator>(</span><span class=number>2</span><span class=space> </span><span class=operator>*</span><span class=space> </span><span class=name>local_smoothing_radius1</span><span class=space> </span><span class=operator>+</span><span class=space> </span><span class=number>1</span><span class=operator>)</span><span class=operator>*</span><span class=operator>*</span><span class=number>2</span><span class=space> </span><span class=operator>/</span><span class=space> </span><span class=operator>(</span><span class=number>9</span><span class=space> </span><span class=operator>*</span><span class=space> </span><span class=name>pi</span><span class=operator>)</span></span></span><span class="text"> if not given</span></div></ul></li><li class="parameteritem"><span class="parameter">local_smoothing_sigma_sq2</span> (<i>float</i>)<ul><div class="parameterdescription"><span class="text">Squared sigma value for confidence computation</span></div></ul></li><li class="parameteritem"><span class="parameter">local_smoothing_sigma_sq3</span> (<i>float</i>)<ul><div class="parameterdescription"><span class="text">Squared sigma value for low frequency alpha computation </span><span class="text">Defaults to </span><span class="inline_code"><span class="codeinline"><span class=operator>(</span><span class=number>2</span><span class=space> </span><span class=operator>*</span><span class=space> </span><span class=name>local_smoothing_radius3</span><span class=space> </span><span class=operator>+</span><span class=space> </span><span class=number>1</span><span class=operator>)</span><span class=operator>*</span><span class=operator>*</span><span class=number>2</span><span class=space> </span><span class=operator>/</span><span class=space> </span><span class=operator>(</span><span class=number>9</span><span class=space> </span><span class=operator>*</span><span class=space> </span><span class=name>pi</span><span class=operator>)</span></span></span><span class="text"> if not given</span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">alpha</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated alpha matte</span></div></ul></li><li class="parameteritem"><span class="parameter">foreground</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated foreground</span></div></ul></li><li class="parameteritem"><span class="parameter">background</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Estimated background</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>image</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"RGB"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>trimap</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>load_image</span><span class=operator>(</span><span class=string>"data/lemur/lemur_trimap.png"</span><span class=operator>,</span><span class=space> </span><span class=string>"GRAY"</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>alpha</span><span class=operator>,</span><span class=space> </span><span class=name>foreground</span><span class=operator>,</span><span class=space> </span><span class=name>background</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>estimate_alpha_sm</span><span class=operator>(</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>image</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>trimap</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>return_foreground_background</span><span class=operator>=</span><span class=keyword>True</span><span class=operator>,</span><span class=space>
</span><span class=indentation>... </span><span class=space> </span><span class=name>sample_gathering_angles</span><span class=operator>=</span><span class=number>4</span><span class=operator>)</span></div></div></div></div></div><footer>© Copyright 2023, Thomas Germer, Tobias Uelwer, Stefan Conrad, Stefan Harmeling</footer></div><script src="/auto-render.min.js" onload="renderMathInElement(document.body)"></script></body></html>