fix(formatting): Zhang-Suen | Rosetta Code (#35472)

* fix(formatting): Move challenge instructions to instruction section

* Fix table and list

* fix(curriculum): Zhangsuen

* fix(curriculum): add bold tags

* Fix typo in instructions
This commit is contained in:
The Coding Aviator
2019-03-18 13:49:02 +05:30
committed by Kristofer Koishigawa
parent 117e198b1e
commit 17715a795e

View File

@ -25,7 +25,7 @@ For example, with an input image of:
######## ####### ###### ################## ###### ######## ####### ###### ################## ######
######## ####### ###### ################ ###### ######## ####### ###### ################ ######
######## ####### ###### ############# ###### ######## ####### ###### ############# ######
</pre> </pre>
It produces the thinned output: It produces the thinned output:
<pre> <pre>
@ -44,49 +44,52 @@ It produces the thinned output:
# ############ # ############
### ### ### ###
</pre> </pre>
<h2>Algorithm</h2> <h2>Algorithm</h2>
Assume black pixels are one and white pixels zero, and that the input image is a rectangular N by M array of ones and zeroes. Assume black pixels are one and white pixels zero, and that the input image is a rectangular N by M array of ones and zeroes.
The algorithm operates on all black pixels P1 that can have eight neighbours. The neighbours are, in order, arranged as: The algorithm operates on all black pixels P1 that can have eight neighbours. The neighbours are, in order, arranged as:
<table border="1">
<tr><td>P9</td><td>P2</td><td>P3</td></tr> <table border="3">
<tr><td>P8</td><td><b>P1</b></td><td>P4</td></tr> <tr><td style="text-align: center;">P9</td><td style="text-align: center;">P2</td><td style="text-align: center;">P3</td></tr>
<tr><td>P7</td><td>P6</td><td>P5</td></tr> <tr><td style="text-align: center;">P8</td><td style="text-align: center;"><b>P1</b></td><td style="text-align: center;">P4</td></tr>
<tr><td style="text-align: center;">P7</td><td style="text-align: center;">P6</td><td style="text-align: center;">P5</td></tr>
</table> </table>
Obviously the boundary pixels of the image cannot have the full eight neighbours. Obviously the boundary pixels of the image cannot have the full eight neighbours.
<ul>
Define $A(P1)$ = the number of transitions from white to black, (0 -> 1) in the sequence P2,P3,P4,P5,P6,P7,P8,P9,P2. (Note the extra P2 at the end - it is circular). <li>Define $A(P1)$ = the number of transitions from white to black, (0 -> 1) in the sequence P2, P3, P4, P5, P6, P7, P8, P9, P2. (Note the extra P2 at the end - it is circular).</li>
<li>Define $B(P1)$ = the number of black pixel neighbours of P1. ( = sum(P2 .. P9) )</li>
</ul>
Define $B(P1)$ = the number of black pixel neighbours of P1. ( = sum(P2 .. P9) )
<h3>Step 1:</h3> <h3>Step 1:</h3>
All pixels are tested and pixels satisfying all the following conditions (simultaneously) are just noted at this stage. All pixels are tested and pixels satisfying all the following conditions (simultaneously) are just noted at this stage.
(0) The pixel is black and has eight neighbours <ol>
(1) $2 <= B(P1) <= 6$ <li>The pixel is black and has eight neighbours</li>
(2) $A(P1) = 1$ <li>$2 <= B(P1) <= 6$</li>
(3) At least one of P2 and P4 and P6 is white <li>$A(P1) = 1$</li>
(4) At least one of P4 and P6 and P8 is white <li>At least one of <b>P2, P4 and P6</b> is white</li>
<li>At least one of <b>P4, P6 and P8</b> is white</li>
</ol>
After iterating over the image and collecting all the pixels satisfying all step 1 conditions, all these condition satisfying pixels are set to white. After iterating over the image and collecting all the pixels satisfying all step 1 conditions, all these condition satisfying pixels are set to white.
<h3>Step 2:</h3> <h3>Step 2:</h3>
All pixels are again tested and pixels satisfying all the following conditions are just noted at this stage. All pixels are again tested and pixels satisfying all the following conditions are just noted at this stage.
(0) The pixel is black and has eight neighbours <ol>
(1) $2 <= B(P1) <= 6$ <li>The pixel is black and has eight neighbours</li>
(2) $A(P1) = 1$ <li>$2 <= B(P1) <= 6$</li>
(3) At least one of P2 and P4 and '''P8''' is white <li>$A(P1) = 1$</li>
(4) At least one of '''P2''' and P6 and P8 is white <li>At least one of <b>P2, P4 and P8</b> is white</li>
<li>At least one of <b>P2, P6 and P8</b> is white</li>
</ol>
After iterating over the image and collecting all the pixels satisfying all step 2 conditions, all these condition satisfying pixels are again set to white. After iterating over the image and collecting all the pixels satisfying all step 2 conditions, all these condition satisfying pixels are again set to white.
Iteration: <h3>Iteration:</h3>
If any pixels were set in this round of either step 1 or step 2 then all steps are repeated until no image pixels are so changed. If any pixels were set in this round of either step 1 or step 2 then all steps are repeated until no image pixels are so changed.
<p>
Task:
Write a routine to perform Zhang-Suen thinning on an image matrix of ones and zeroes.
</p>
</section> </section>
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
Write a routine to perform Zhang-Suen thinning on the provided image matrix.
</section> </section>
## Tests ## Tests