Why does skeletonization sometimes reduce horizontal rectangles to single pixels?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Skeletonization (bwskel) of a horizontal rectangle may sometimes result in a single pixel. Can anybody explain why (the logics) and what to do to resolve this issue (illustrated below)?
-------------
Create black binary image and add four white rectangles
bw = false(30,55);
bw(5:9,5:15) = true; % Placed NW
bw(5:9,30:51) = true; % Placed NE
bw(20:25,5:15) = true; % Placed SW
bw(20:25,30:51) = true; % Placed SE
Show image and corresponding skeletonized image
imshow(bw)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225690/image.png)
imshow(bwskel(bw))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225691/image.png)
For two of the rectangles the skeletons reduce to single pixels. Why?
The same thing does not happen for 45 degr. rotated rectangles.
Rotated version of image
bwrot = imrotate(bw,45);
Show rotated images and its skeletonized counterpart
imshow(bwrot)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225692/image.png)
imshow(bwskel(bwrot))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225693/image.png)
For 90 degr. rotated rectangles the same two rectangles reduces to single pixels when skeletonized. However, the pixels are now placed differently.
bwrot = imrotate(bw,90);
Show rotated images and its skeletonized counterpart
imshow(bwrot)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225694/image.png)
imshow(bwskel(bwrot))
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/225695/image.png)
0 Commenti
Risposta accettata
Matt J
il 20 Giu 2019
Modificato: Matt J
il 20 Giu 2019
It is because the lower rectangles have an even number of rows, so their "center line" in continuous space does not coincide with the centers of a line of pixels.
To resolve, make the number of rows odd, e.g.,
bw = false(30,55);
bw(5:9,5:15) = true; % Placed NW
bw(5:9,30:51) = true; % Placed NE
bw(21:25,5:15) = true; % Placed SW
bw(21:25,30:51) = true; % Placed SE
3 Commenti
Matt J
il 21 Giu 2019
It's a mystery to me. Fortunately, though, if we loop over the odd numbers,
for recth = 1:2:maxrecth
a line skeleton is always observed.
Più risposte (1)
Catalytic
il 20 Giu 2019
Remember what bwskel is doing. It is peeling the outer pixels of the rectangles like an onion over and over again until it reaches a shape that is 1 pixel wide. Because the bottom 2 rectangles have an even number of pixel rows, this process can be repeated until the shape essentially disappears.
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!