天天看點

基于matlab的區域生長算法實作

利用區域生長算法進行圖像分割

算法步驟

  1. 滑鼠點選選取生長點
  2. 3*3 8-鄰域生長
  3. 生長準則:圖像與生長點灰階差小于門檻值
  4. 生長點壓入棧中,直到棧中沒有元素時停止
I=imread('mountain.png');

if isinteger(I)
    I=im2double(I);
end
I = rgb2gray(I);

figure 
imshow(I)
[M,N]=size(I);
[y,x]=getpts; %單擊取點後,按enter結束
x1=round(x);
y1=round(y);
seed=I(x1,y1); %擷取中心像素灰階值

J=zeros(M,N);
J(x1,y1)=1;

count=1; %待處理點個數
threshold=0.15;
while count>0
    count=0;
    for i=1:M %周遊整幅圖像
    for j=1:N
        if J(i,j)==1 %點在“棧”内
        if (i-1)>1&(i+1)<M&(j-1)>1&(j+1)<N %3*3鄰域在圖像範圍内
            for u=-1:1 %8-鄰域生長
            for v=-1:1
                if J(i+u,j+v)==0&abs(I(i+u,j+v)-seed)<=threshold
                    J(i+u,j+v)=1;
                    count=count+1;  %記錄此次新生長的點個數
                end
            end
            end
        end
        end
    end
    end
end

subplot(1,2,1),imshow(I);
title("original image")
subplot(1,2,2),imshow(J);
title("segmented image")

           

處理結果

基于matlab的區域生長算法實作
基于matlab的區域生長算法實作
基于matlab的區域生長算法實作

參考

https://blog.csdn.net/qq_35608277/article/details/78598016

繼續閱讀