通过重构Matlab代码进行形态学开放 [英] morphological opening by reconstruction matlab code

查看:56
本文介绍了通过重构Matlab代码进行形态学开放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该通过自己的Matlab代码而不是 imreconstruct 进行重构来进行形态学开放.这是我的代码,但效果不佳:

I should do morphological opening by reconstruction by my own Matlab code not imreconstruct. this is my code but it is not work well:

S = input('Enter the structuring element: ');
Im = input('Enter the input image: ');

marker = imerode(Im,S);
mask = Im;

Im2 = imdilate(marker,S);
Im3 = min(Im2,Im);

i=1;

while Im3(i+1)~= Im3(i)
    i=i+1;
    Im2 = imdilate(Im3(i),S);
    Im3(i+1) = min(Im2,Im);
end

imrecon = Im3;

有人有更好的代码或可以编辑我的代码吗?请帮我.预先谢谢你.

has anyone a better code or can edit my code? please help me. Thank you in advance.

推荐答案

我不知道MatLab,但是您的代码似乎正确.但请注意,您必须检查用户是否给出了单一的结构化元素(最大3x3尺寸).

I don't know MatLab, but your code seems correct. But be careful, you have to check that the user gives an unitary structuring element (3x3 dimensions max).

这是通过重建而打开的经典伪代码:

Here is the classical pseudo-code for an opening by reconstruction:

Input: Image, Marker, SE (unitary, 3x3 maximum)
Var: Reconstructed, Dilated
Output: Result

Reconstructed <-- Marker

while Reconstructed != Result
    Result <-- Reconstructed
    Dilated <-- Dilate(Result, SE)
    Reconstructed <-- Minimum(Image, Dilated)

这是实现这一目标的学术方法,但绝对不是最快的方法.一种更快的方法是使用分层等待队列(HQ)来实现它.将标记像素输入到HQ中,然后像以前一样一遍一遍地处理它们:膨胀加最小值.使用HQ,每个像素仅被处理一次.我知道最快的实现使用Down Hill算法(Java的速度快3倍,而c/C ++的速度快20倍),但我还不足以解释它.

That's the academic way to do it, but definitely not the fastest. A faster way is to implement it using a Hierarchical Waiting Queue (HQ). You enter the marker pixel into the HQ, and you process them one by one doing as previously: dilation plus minimum.Using the HQ, each pixel is processed only once. The fastest implementation I know, uses the Down Hill algorithm (3 times faster in Java, and up to 20 in c/C++), but I don't know it enough to explain it.

这篇关于通过重构Matlab代码进行形态学开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆