Thinning: a sequence of four structuring elements, b set A, c to k thinning by each of the structuring elements, l result after convergence, m conversion to m connectivity

1 view (last 30 days)
Thinning: a sequence of four structuring elements, b set A, c to k thinning by each of the structuring elements, l result after convergence, m conversion to m connectivity
kindly wrute the code for this
  1 Comment
DGM
DGM on 23 Dec 2021
There are various ways to do thinning. The methods used by bwskel() and the 'skel' and 'thin' options for bwmorph() differ from the method above.
I'm assuming you're supposed to implement the specific algo described by the book. On that assumption, you're the one with the book that tells you how to do it. All we have is a picture without any context.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 22 Dec 2021
skeletonImage = bwskel(binaryImage);

DGM
DGM on 23 Dec 2021
Edited: DGM on 23 Dec 2021
Let's assume that the image is confusingly backwards and that black is true and white is false. This is what the existing tools do:
inpict = true(5,10);
inpict([20 25 42:45 47:50]) = false
inpict = 5×10 logical array
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0
A1 = bwskel(inpict)
A1 = 5×10 logical array
0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
A2 = bwmorph(inpict,'skel',inf)
A2 = 5×10 logical array
1 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0
A3 = bwmorph(inpict,'thin',inf)
A3 = 5×10 logical array
0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The 'skel' method used by bwmorph() differs from bwskel() and might be closer in concept and result to what's intended. That said, bwmorph() does not perform the same operations as suggested in the book. The following is derived from the MIMT implementation and produces the same result as bwmorph() with yet another approach.
% index weighting array
seb=2.^([1 4 7; 2 5 8; 3 6 9]-1);
% sums resultant from correlation
keysums={[89 91 217 219],[152 153 216 217 408 409 472 473],[23 31 55 63],[26 27 30 31 90 91 94 95], ...
[464 472 496 504],[50 51 54 55 306 307 310 311],[308 310 436 438],[176 180 240 244 432 436 496 500]};
% apply the filter set this many times
numpasses = 10;
B = uint16(inpict);
for k = 1:numpasses
priorresult = logical(B);
% core filter application
for p = 1:8
B = uint16(B & ~ismember(imfilter(B,seb),keysums{p}));
end
% exit early if image has reached steady-state
if numpasses>1 % don't bother testing unless we're going to loop anyway
thisresult = logical(B);
changedpixels = thisresult~=priorresult;
if ~any(changedpixels(:)) % if nothing changed since last pass, don't bother continuing
break;
end
end
end
% show the result
B
B = 5×10
1 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0
Again, if you want something that matches the book, you're the one with the book.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!