Skip to content This repository Search Pull requests Issues Marketplace Explore @burakakde Sign out Watch 0 Star 0 Fork 0 burakakde/MyFirstWebsite Code Issues 0 Pull requests 0 Projects 0 Wiki Insights Settings Branch: gh-pages Find file Copy pathMyFirstWebsite/education.html eeca46f on Dec 14, 2017 @burakakde burakakde Update education.html 1 contributor RawBlameHistory 552 lines (512 sloc) 23.3 KB Thinning

Thinning

Simple thinning algorithm that uses structuring elements as it is decribed here
Structuring elements are applied using the 'hit - miss' operation till no furher changes are seen. The structuring elements are described by using the code below:

Mat seLeft0 = (Mat_(3, 3) <<-1, -1, -1, 0, 1, 0, 1, 1, 1);
Mat seRight0 = (Mat_(3, 3) << 0, -1, -1, 1, 1, -1, 0, 1, 0);
Mat seLeft90 = (Mat_(3, 3) << 1, 0, -1, 1, 1, -1, 1, 0, -1);
Mat seRight90 = (Mat_(3, 3) << 0, 1, 0, 1, 1, -1, 0, -1, -1);
Mat seLeft180 = (Mat_(3, 3) << 1, 1, 1, 0, 1, 0, -1, -1, -1);
Mat seRight180 = (Mat_(3, 3) << 0, 1, 0, -1, 1, 1, -1, -1, 0);
Mat seLeft270 = (Mat_(3, 3) << -1, 0, 1, -1, 1, 1, -1, 0, 1);
Mat seRight270 = (Mat_(3, 3) << -1, -1, 0, -1, 1, 1, 0, 1, 0);

In the next step, structural elements are applied by using morphologyEx
morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft0);
Then result of operation, which is (foo) above, is substracted from input image (dst_bin) so that the input image is updated. Substraction is done by the line below.
dst_bin = dst_bin - foo;
You can refer to the figures below for input image and the resulting output (foo).

hon outseLeft0 outseLeft90
Left: Input image (dst_bin). Middle: foo which is output of morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft0). Right: foo which is output of morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft90);

The effect of subtracting the foo's from the input (dst_bin) in the array of images below.
dst_bin5 dst_bin10 dst_bin15 dst_bin20 dst_bin25 result
From left to right result of iterations 5, 10, 15, 20, 25 and 29 (final) respectively.

Above results are obtained by using the loop below.

int ctr{ 0 };
while (true)
{
ctr++;
cout << "Iteration " << ctr << endl;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft0);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seRight0);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft90);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seRight90);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft180);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seRight180);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seLeft270);
dst_bin = dst_bin - foo;
morphologyEx(dst_bin, foo, MORPH_HITMISS, seRight270);
if (countNonZero(foo) == 0) break;
dst_bin = dst_bin - foo;
}


ctr is just a counter that keeps track of number of iteration while the line below breaks the loop if no further changes are seen.
if (countNonZero(foo) == 0) break;
You can find the source code here
© 2018 GitHub, Inc. Terms Privacy Security Status Help Contact GitHub API Training Shop Blog About