A 'cut-n-paste' version of the commented command...
Code: Select all
convert 8-connectivity.png -verbose -virtual-pixel white \
-print "Fill 'v' junctions to 't' junstions\n" \
-morphology thicken '3>:-,0,-,1,-,1,0,1,0' \
-print "Fill in diagonal pixels to obtain 4-connectivity\n" \
-morphology thicken '3>:-,0,0,1,-,0,0,1,-' \
-print "Use skeleton:3 to 'thin' 2x2 filled blocks\n" \
-morphology thinning Skeleton:3 \
4conn.png
But thank you for the example. Note I added the VP white, though it is not needed for this example.
We currently have a total of 4+4+12 kernel passes.
The skeleton kernel may possibly be reduced but we would need to examine the 2x2 blocks that were generated.
According to the verbose output there was 2 such 'thinnings' performed.
Were these at 'v' -> 't' junctions?
Also the second thicken (fill diagonal), should not need the 3rd and 4th kernel to thicken diagonal lines! And yet the the 4th kernel produces 2 such thickens. We will need to example those cases to determine why.
Perhaps it was these thickens that produces the 2 sets of 2x2 blocks that was later removed by the skeletion thin?
In any case total added pixels is... 716, followed by 2 removals.
Hmmm... My version on your image produced different results!
Fill 'v' junctions to 't' junstions
Thicken:1.0 #1 => Changed 4 (re-iterate)
Thicken:1.1 #2 => Changed 5 (re-iterate)
Thicken:1.2 #3 => Changed 5 (re-iterate)
Thicken:1.3 #4 => Changed 5 (done)
Fill in diagonal pixels to obtain 4-connectivity
Thicken:1.0 #1 => Changed 372 (re-iterate)
Thicken:1.1 #2 => Changed 319 (re-iterate)
Thicken:1.2 #3 => Changed 1 (re-iterate)
Thicken:1.3 #4 => Changed 3 (done)
Use skeleton:3 to 'thin' 2x2 filled blocks
Thinning:1.0 #1 => Changed 0 (re-iterate)
Thinning:1.1 #2 => Changed 0 (re-iterate)
Thinning:1.2 #3 => Changed 0 (re-iterate)
Thinning:1.3 #4 => Changed 0 (re-iterate)
Thinning:1.4 #5 => Changed 0 (re-iterate)
Thinning:1.5 #6 => Changed 0 (re-iterate)
Thinning:1.6 #7 => Changed 0 (re-iterate)
Thinning:1.7 #8 => Changed 0 (re-iterate)
Thinning:1.8 #9 => Changed 0 (re-iterate)
Thinning:1.9 #10 => Changed 1 (re-iterate)
Thinning:1.10 #11 => Changed 0 (re-iterate)
Thinning:1.11 #12 => Changed 0 (done)
8-connectivity.png=>4conn.png PNG 224x215 224x215+0+0 8-bit PseudoClass 2c 0.050u 0:00.030
Oh. A 'flicker_cmp' (Script download from
http://www.imagemagick.org/Usage/scripts/flicker_cmp )
of the two images show 3 different 'edge effects' between your version and mine. Adding VP distorted the image less in two spots, though it removed a single isolated edge pixel on the bottom edge for the third 'edge effect'.
NOTE a flicker-cmp of the 8 image to the results show a distinct 1/2 pixel move of diagonal lines in a easterly direction. This is to be expected as part of the thicken process. If you also implement the reverse, I would ensure that that has the opposite preference.
I'll add these kernels as named kernels into IM (both IMv6 and IMv7) next time I get a chance to do some programming.