From 17715a795e39e7f1ce2323ed7e15cd6e3400ed0d Mon Sep 17 00:00:00 2001
From: The Coding Aviator <34807532+thecodingaviator@users.noreply.github.com>
Date: Mon, 18 Mar 2019 13:49:02 +0530
Subject: [PATCH] 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
---
.../zhang-suen-thinning-algorithm.english.md | 57 ++++++++++---------
1 file changed, 30 insertions(+), 27 deletions(-)
diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.english.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.english.md
index 66bc223c2f..4645cefec6 100644
--- a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.english.md
+++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/zhang-suen-thinning-algorithm.english.md
@@ -25,7 +25,7 @@ For example, with an input image of:
######## ####### ###### ################## ######
######## ####### ###### ################ ######
######## ####### ###### ############# ######
-
+
It produces the thinned output:
@@ -44,49 +44,52 @@ It produces the thinned output:
# ############
### ###
-
+
+
Algorithm
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:
-
- P9 | P2 | P3 |
- P8 | P1 | P4 |
- P7 | P6 | P5 |
+
+
+ P9 | P2 | P3 |
+ P8 | P1 | P4 |
+ P7 | P6 | P5 |
+
Obviously the boundary pixels of the image cannot have the full eight neighbours.
-
- 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).
-
-
- Define $B(P1)$ = the number of black pixel neighbours of P1. ( = sum(P2 .. P9) )
+
+ - 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).
+ - Define $B(P1)$ = the number of black pixel neighbours of P1. ( = sum(P2 .. P9) )
+
Step 1:
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
- (1) $2 <= B(P1) <= 6$
- (2) $A(P1) = 1$
- (3) At least one of P2 and P4 and P6 is white
- (4) At least one of P4 and P6 and P8 is white
+
+ - The pixel is black and has eight neighbours
+ - $2 <= B(P1) <= 6$
+ - $A(P1) = 1$
+ - At least one of P2, P4 and P6 is white
+ - At least one of P4, P6 and P8 is 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.
+
Step 2:
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
- (1) $2 <= B(P1) <= 6$
- (2) $A(P1) = 1$
- (3) At least one of P2 and P4 and '''P8''' is white
- (4) At least one of '''P2''' and P6 and P8 is white
+
+ - The pixel is black and has eight neighbours
+ - $2 <= B(P1) <= 6$
+ - $A(P1) = 1$
+ - At least one of P2, P4 and P8 is white
+ - At least one of P2, P6 and P8 is 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:
+Iteration:
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.
-
-Task:
-Write a routine to perform Zhang-Suen thinning on an image matrix of ones and zeroes.
-
## Instructions
-
+Write a routine to perform Zhang-Suen thinning on the provided image matrix.
## Tests