Smooth Results from bwboundaries

8 ビュー (過去 30 日間)
Holden Tranquillo
Holden Tranquillo 2022 年 4 月 6 日
回答済み: Image Analyst 2025 年 3 月 6 日
Hello All,
I have seen others ask this question on the forum, but was unable to find the answer for my problem. I am using 'bwboundaries.m' to find contours on an image I import to Matlab. I then use the contours to write them to STL files.
However, the boundaries that are found using bwboundaries are very rough and jagged when zoomed in, which is not the ideal result. I need something smooth to work with. I have attached pictures of the issue and the code, would love some help.
Thanks

回答 (2 件)

Shreshth
Shreshth 2025 年 3 月 6 日
Hi Holden,
As per my understanding, you would like to enhance the capability so that you do not see the detected boundary jagged.
In every image when zoomed in to a certain level, there will jaggedness which will lead to boundary detection algorithm to work up to a certain extent. The zooming beyond the threshold will result in jaggedness.
I hope this resolves the issue you were facing.

Image Analyst
Image Analyst 2025 年 3 月 6 日
If you want to smooth boundaries you can use splines or pchip. I'm attaching demos.
Another option if you have a binary image that you're using bwboundaries on, then you can blur the image with imfilter or conv2 and then threshold at 0.5 to get a smoother mask, then use bwboundaries on that. Of course the image will look jaggy if you zoom in enough but the plotted boundary will be pretty smooth. If you need it even smoother, increase the sampling rate in the interpolating functions (less distance between sampling points will give smoother boundaries).

Community Treasure Hunt

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

Start Hunting!

Translated by