平滑分割图像的线条

发布于 2024-08-15 06:53:40 字数 168 浏览 4 评论 0原文

替代文本

您好, 我有一个如图所示的分割图像。有没有办法让线条变得平滑,使其看起来不那么波浪状?谢谢。

alt text

Hello,
I have a segmented image as shown. Is there a way to smoothen the lines so that it does not look so wavy? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苯莒 2024-08-22 06:53:40

以下代码需要图像处理工具箱:

url = 'http://i182.photobucket.com/albums/x11/veronicafmy/FYP/picture5segmentedimage.jpg';
rgb = imread(url);
bw = im2bw(rgb2gray(rgb), 0.5);
se = strel('line',50,74); % 74 degrees determined by inspection
bw2 = imclose(bw,se);
se2 = strel('line',50,74+90);
bw3 = imclose(bw2,se2);

这是结果:

smoothed result

可选步骤:通过细化进行后处理:

bw4 = bwmorph(bw3,'thin',inf);

The following code requires Image Processing Toolbox:

url = 'http://i182.photobucket.com/albums/x11/veronicafmy/FYP/picture5segmentedimage.jpg';
rgb = imread(url);
bw = im2bw(rgb2gray(rgb), 0.5);
se = strel('line',50,74); % 74 degrees determined by inspection
bw2 = imclose(bw,se);
se2 = strel('line',50,74+90);
bw3 = imclose(bw2,se2);

Here's the result:

smoothed result

Optional step: postprocess by thinning:

bw4 = bwmorph(bw3,'thin',inf);
时光礼记 2024-08-22 06:53:40

我认为你应该问自己为什么它必须更平滑。如果您已经分割了图像并获得了该结果,您确定平滑会给您带来正确的结果吗?
如果确实如此,那么史蒂夫·埃丁的回答似乎就成功了。

另一方面,如果您尝试分割的对象比结果平滑得多,我建议采用两种方法之一。

  1. 如果目标对象是一个十字(两条线),我可能会计算这些线并将表示形式更改为两条线段。然后可以以任何精度和平滑度渲染它们。为此,您可以使用某种特征检测算法找到中心和旋转,也可以使用霍夫变换来找到线条。后者可能要简单得多。

  2. 如果目标可以具有任何形式,那么我会研究更好的分割算法。有些分割算法不基于硬阈值。我为此使用了图形分区算法,虽然速度较慢,但​​效果很好。

I think you should ask yourself why it has to be smoother. If you have segmented an image and gotten that result, are you sure that smoothening will give you a correct result?
If it does then Steve Eddins answer seems to do the trick.

If, on the other hand, the object you are trying to segment is much smoother than the result I'd suggest one of two approaches.

  1. If the target object is a cross (two lines), I'd probably calculate the lines and change the representation to two line segments. These can then be rendered at whatever precision and smoothness. To do this you could either find the center and rotation using some kind of feature detection algorithm, or you could use hough transforms to find the lines. The latter is probably much simpler.

  2. If the target can have any form then I'd look into a better segmentation algorithm. There are segmentation algorithms that is not based on hard thresholds. I have used graph partitioning algorithms for this, and while slow, they work well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文