problem in seeded region growing algorithm
    5 次查看(过去 30 天)
  
       显示 更早的评论
    

I am trying to implement seed region growing algorithm but its not giving proper output.Please help me solve the error..
here is my code..
clc;clear all;close all;
r=imread('e:\IMAGES\pears.jpg'); % read the image
[rows columns numberOfColorChannels] = size(r);
if numberOfColorChannels > 1
  r = rgb2gray(r); % converting image to grayscale
else
  r = r; % It's already gray.
end
[row col]=size(r)
g=zeros(row,col);
I=zeros(size(r));
I=r;
S=zeros(size(r));
S(80:82,172:174)=ones(3,3); %initial seed image
figure,imshow(S),title('Initial Seed Image')
T=50; %threshold value
r=double(r);
w = [1 1 1;1 1 1;1 1 1 ];  
SI=size(r)
p=size(r);
for x=2:1:p(1)-1
  for y=2:1:p(2)-1  
      a1=[w(1)*S(x-1,y-1) w(2)*S(x-1,y) w(3)*S(x-1,y+1) w(4)*S(x,y-1) w(5)*S(x,y) w(6)*S(x,y+1) w(7)*S(x+1,y-1) w(8)*S(x+1,y) w(9)*S(x+1,y+1)];
      AI(x,y)=min(a1);
  end
end
SI= padarray(AI,[1 1],'symmetric','post')
SI=uint8(SI)
J=find(SI); 
S1=r(J);  % seed value obtained from SI
seedvalue=S1;
S=abs(r- seedvalue)<= T; % thresholding the absolute difference between original image & seed value
figure,imshow(S),title('thresholding output')
      for p=1:1:row
      for q=1:1:col
          if(SI(p,q)==1)
              for n=q:1:col
              if S(p,q)==S(p,n)
                  g(p,n)=1;
              end
              end
              for n=q:(-1):1
              if S(p,q)==S(p,n)
                  g(p,n)=1;
              end
              end
              for n=p:-1:1
              if S(p,q)==S(n,q)
                  g(n,q)=1;
              end
              end
              for n=p:1:row
              if S(p,q)==S(n,q)
                  g(n,q)=1;
              end
              end
             for n1=p:1:row
               for  n2=q:1:col
              if S(p,q)==S(n1,n2)
                  g(n1,n2)=1;
              end
              end
              end
              for n1=p:1:row
               for   n2=q:(-1):1
              if S(p,q)==S(n1,n2)
                  g(n1,n2)=1;
              end
              end
              end
              for n1=p:-1:1
               for   n2=q:(-1):1
              if S(p,q)==S(n1,n2)
                  g(n1,n2)=1;
              end
              end
              end
                for n1=p:-1:1
                for  n2=q:1:col
              if S(p,q)==S(n1,n2)
                  g(n1,n2)=1;
                  end
              end
              end
              end
              end
          end
g=uint8(g)
SE = ones(1,1);
g =bwlabel(imdilate(g,SE),8);%reconstructing the image
%g=logical(g)
%I(g)=0
%figure,imshow(I),title('Final Output')
Lrgb = label2rgb(g);
figure, imshow(Lrgb)
title('output of region growing process')
figure, imshow(I), hold on
himage = imshow(Lrgb);
set(himage, 'AlphaData', 0.3);
title('final output superimposed on original image')
10 个评论
  Hanz Ero
 2020-3-29
				aarti sawant, can you help me, please give your code to me for the sake of college.
回答(1 个)
  renugadevi ramadoss
 2016-8-9
        i have a doubt in setting initial seed points using seed determination for segmentation.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




