problem in seeded region growing algorithm
显示 更早的评论

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 个评论
Walter Roberson
2014-1-1
How does the output you are seeing differ from the output you expect? Is there an error message?
Image Analyst
2014-1-1
编辑:Image Analyst
2014-1-1
I ran it and it looks like it ran fine to me. All the pears in figure2 that were touching the seed point and touching each other got selected as the same object in subsequent images, which is what it should do. So, what's the problem? You'd get the same thing just calling bwlabel() or bwconncomp() on your binary image.
aarti sawant
2014-1-2
Image Analyst
2014-1-2
Well then your binary image is wrong, and that is calculated before you even start the region growing. All those other pears are connected to the seed pear in your binary image.
Anyway, if you have a seed point, you don't need to do all that stuff you did since there is a function in the Image Processing Toolbox that does all that for you in one line. It's called imreconstruct (). But of course, it also requires that you have the pears separated before calling it just like your algorithm does.
aarti sawant
2014-1-2
Image Analyst
2014-1-2
You can write your own region growing, or labeling, code as you did. Are you not seeing how, in your binary image, that the vast majority of the pears in your image area connected by white pathways to the pear where you placed the seed? Please let me know if you realize that. And if you do, why you don't think your growing code will reach out to all of those?
aarti sawant
2014-1-3
Image Analyst
2014-1-3
I'm not sure how else to say it. What do you think region growing does? It captures (labels) all pixels that are connected to the seed pixel according to some criteria, like they have the same or similar gray level. You have just a binary image. You have about 3 or 4 white binary blobs, not 2 dozen pears. Look at your binary image - see? Just 3 blobs. That one gigantic blob that takes up almost your whole image? It's right over your seed point so that whole gigantic blob is going to be selected. Why should it get just the pear over the seed? According to your binary image that you are using, that pear is physically connected to the next one, and the next one, and the next one after that. Virtually all of them are connected. I suggest you look at how you came up with that binary image. And I suggest you look at this example of marker controlled watershed segmentation, which luckily for you is done with the pears demo image. http://matlab.wikia.com/wiki/FAQ#After_installation.2C_MATLAB_crashes_or_gives_an_error_message_when_I_try_to_run_MATLAB.
aarti sawant
2014-1-3
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
0 个投票
i have a doubt in setting initial seed points using seed determination for segmentation.
1 个评论
Walter Roberson
2016-8-23
Please explain your doubt further.
类别
在 帮助中心 和 File Exchange 中查找有关 Morphological Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!