mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-05 06:37:35 +08:00
64 lines
16 KiB
HTML
64 lines
16 KiB
HTML
Image Segmentation
|
||
<div class="ques-view"><p>Image segmentation is usually formulated as a graph partition problem, where each segment corresponds to a connected component. Moreover, each pixel is the vertex of the graph. Each edge has a weight, which is a non-negative dissimilarity between neighboring pixels. So, the goal of image segmentation is to decompose the image graph into several disconnected components, where the elements in a component are similar and the elements in the different components are dissimilar.</p>
|
||
<p>The components are defined as follows: </p>
|
||
<ul>
|
||
<li>A component is made of a set of connected vertices;</li>
|
||
<li>Any two components have no shared vertices;</li>
|
||
<li>The dissimilarity <span class="katex"><span class="katex-mathml"><math><mrow><mi>D</mi><mo>(</mo><mi>C</mi><mn>1</mn><mo separator="true">,</mo><mi>C</mi><mn>2</mn><mo>)</mo></mrow>D(C1, C2)</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">1</span><span class="mpunct">,</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">2</span><span class="mclose">)</span></span></span></span> of any two components <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi><mn>1</mn></mrow>C1</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">1</span></span></span></span> and <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi><mn>2</mn></mrow>C2</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">2</span></span></span></span> is larger than the confidence <span class="katex"><span class="katex-mathml"><math><mrow><mi>H</mi></mrow>H</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.08125em;">H</span></span></span></span> of any of <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi><mn>1</mn></mrow>C1</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">1</span></span></span></span> and <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi><mn>2</mn></mrow>C2</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">2</span></span></span></span>. </li>
|
||
<li>The dissimilarity <span class="katex"><span class="katex-mathml"><math><mrow><mi>D</mi><mo>(</mo><mi>C</mi><mn>1</mn><mo separator="true">,</mo><mi>C</mi><mn>2</mn><mo>)</mo></mrow>D(C1, C2)</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.02778em;">D</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">1</span><span class="mpunct">,</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">2</span><span class="mclose">)</span></span></span></span> is defined to be the minimum edge weight of all the edges connecting <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi><mn>1</mn></mrow>C1</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">1</span></span></span></span> and <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi><mn>2</mn></mrow>C2</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">2</span></span></span></span>, or infinity if no such edge exists;</li>
|
||
<li>The confidence of a component <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi></mrow>C</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span></span></span></span>, <span class="katex"><span class="katex-mathml"><math><mrow><mi>H</mi><mo>(</mo><mi>C</mi><mo>)</mo></mrow>H(C)</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.08125em;">H</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mclose">)</span></span></span></span>, is defined to be the maximum edge weight of the minimum spanning tree of <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi></mrow>C</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span></span></span></span>, plus a function <span class="katex"><span class="katex-mathml"><math><mrow><mi>f</mi><mo>(</mo><mi>C</mi><mo>)</mo><mo>=</mo><mi>c</mi><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><mi>C</mi><mi mathvariant="normal">∣</mi></mrow>f(C) = c/|C|</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mclose">)</span><span class="mrel">=</span><span class="mord mathit">c</span><span class="mord mathrm">/</span><span class="mord mathrm">∣</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">∣</span></span></span></span> where <span class="katex"><span class="katex-mathml"><math><mrow><mi>c</mi></mrow>c</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.43056em;"></span><span class="strut bottom" style="height:0.43056em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">c</span></span></span></span> is a positive constant and <span class="katex"><span class="katex-mathml"><math><mrow><mi mathvariant="normal">∣</mi><mi>C</mi><mi mathvariant="normal">∣</mi></mrow>|C|</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">∣</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mord mathrm">∣</span></span></span></span> is the size of the component <span class="katex"><span class="katex-mathml"><math><mrow><mi>C</mi></mrow>C</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.07153em;">C</span></span></span></span>;</li>
|
||
<li>A set of vertices must not be treated as a component if they can be partitioned into two or more components.</li>
|
||
</ul>
|
||
<p>Your job is to write a program to list all the components.</p>
|
||
<h3 id="input-specification-">Input Specification:</h3>
|
||
<p>Each input file contains one test case. For each case, the first line contains three integers: <span class="katex"><span class="katex-mathml"><math><mrow><msub><mi>N</mi><mi>v</mi></msub></mrow>N_v</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:-0.10903em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight" style="margin-right:0.03588em;">v</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span></span></span></span> (<span class="katex"><span class="katex-mathml"><math><mrow><mn>0</mn><mo><</mo><msub><mi>N</mi><mi>v</mi></msub><mo>≤</mo><mn>1</mn><mn>0</mn><mn>0</mn><mn>0</mn></mrow>0 < N_v \le 1000</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mrel"><</span><span class="mord"><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:-0.10903em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight" style="margin-right:0.03588em;">v</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span><span class="mrel">≤</span><span class="mord mathrm">1</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span><span class="mord mathrm">0</span></span></span></span>), the total number of vertices (and hence the vertices are numbered from 0 to <span class="katex"><span class="katex-mathml"><math><mrow><msub><mi>N</mi><mi>v</mi></msub><mo>−</mo><mn>1</mn></mrow>N_v -1</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:-0.10903em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight" style="margin-right:0.03588em;">v</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span><span class="mbin">−</span><span class="mord mathrm">1</span></span></span></span>); <span class="katex"><span class="katex-mathml"><math><mrow><msub><mi>N</mi><mi>e</mi></msub></mrow>N_e</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:-0.10903em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">e</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span></span></span></span>, the total number of edges; and <span class="katex"><span class="katex-mathml"><math><mrow><mi>c</mi></mrow>c</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.43056em;"></span><span class="strut bottom" style="height:0.43056em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">c</span></span></span></span>, the constant in the function <span class="katex"><span class="katex-mathml"><math><mrow><mi>f</mi><mo>(</mo><mi>C</mi><mo>)</mo></mrow>f(C)</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit" style="margin-right:0.07153em;">C</span><span class="mclose">)</span></span></span></span>. Then <span class="katex"><span class="katex-mathml"><math><mrow><msub><mi>N</mi><mi>e</mi></msub></mrow>N_e</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.83333em;vertical-align:-0.15em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathit" style="margin-right:0.10903em;">N</span><span class="msupsub"><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:-0.10903em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span><span class="reset-textstyle scriptstyle cramped mtight"><span class="mord mathit mtight">e</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;"></span></span></span></span></span></span></span></span></span> lines follow, each gives an adge in the format:</p>
|
||
<pre><code>V1 V2 Weight
|
||
</code></pre><p>Note: it is guaranteed that each pixel has no more than 8 neighboring pixels. The constant and all the weights are positive and are no more than 1000.</p>
|
||
<h3 id="output-specification-">Output Specification:</h3>
|
||
<p>For each case, list each component in a line. The vertices in a component must be printed in increasing order, separated by one space with no extra space at the beginning or the end of the line. The components must be listed in increasing order of their first vertex.</p>
|
||
<h3 id="sample-input-1-">Sample Input 1:</h3>
|
||
<pre><code class="lang-in">10 21 100
|
||
0 1 10
|
||
0 3 60
|
||
0 4 90
|
||
1 2 90
|
||
1 3 50
|
||
1 4 200
|
||
1 5 86
|
||
2 4 95
|
||
2 5 5
|
||
3 4 95
|
||
3 6 15
|
||
3 7 101
|
||
4 5 500
|
||
4 6 100
|
||
4 7 101
|
||
4 8 101
|
||
5 7 300
|
||
5 8 50
|
||
6 7 90
|
||
7 8 84
|
||
7 9 34
|
||
</code></pre>
|
||
<h3 id="sample-output-1-">Sample Output 1:</h3>
|
||
<pre><code class="lang-out">0 1 3 6
|
||
2 5 8
|
||
4
|
||
7 9
|
||
</code></pre>
|
||
<h3 id="sample-input-2-">Sample Input 2:</h3>
|
||
<pre><code class="lang-in">7 7 100
|
||
0 1 10
|
||
1 2 61
|
||
2 3 50
|
||
3 4 200
|
||
4 5 82
|
||
5 0 200
|
||
3 6 90
|
||
</code></pre>
|
||
<h3 id="sample-output-2-">Sample Output 2:</h3>
|
||
<pre><code class="lang-out">0 1
|
||
2 3 6
|
||
4 5
|
||
</code></pre>
|
||
</div> |