morphological opening by reconstruction matlab code

不羁的心 提交于 2021-01-28 18:58:40

问题


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.


回答1:


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)

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.



来源:https://stackoverflow.com/questions/37591343/morphological-opening-by-reconstruction-matlab-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!