image segmentation

1 Ansicht (letzte 30 Tage)
pdp rpa
pdp rpa am 24 Mär. 2012
Sir i have been trying the following code for image segmentation using dbscan.
But the problem is that this code is runnung infinite time.I am not getting the solution and it has taken away my sleep. plz sir i really need your help.
This is my project work and the deadline is also very near
he = imread('test.jpg');
ab = double(he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
X = reshape(ab,nrows*ncols,2);
K=6;
[class,type]=dbscannew(X,K)
%The m file for the function dbscannew is given below : dbscannew.m
function [class,type]=dbscannew(X,K,d)
% [class,type]=dbscan(X,K,d)
% X: matrix
% K: minimal points
% d: maximal distance
% class: assignments
% type: core: 1, border: 0, outlier: -1
if nargin<3
d=epsilon(X,K);
end
m=size(X, 1);
class=zeros(m,1);
type=zeros(m,1);
touched=zeros(m,1);
c=1;
for i=1:m
if touched(i) continue; end
indices=find(distances(X(i,:),X)<=d);
k=length(indices);
if k==1
type(i)=-1;
class(i)=-1;
touched(i)=1;
elseif k<=K
type(i)=0;
class(i)=0;
else
type(i)=1;
class(indices)=c;
while ~isempty(indices)
index=indices(1);
touched(index)=1;
I=find(distances(X(index,:),X)<=d);
if length(I)>1
class(I)=c;
if length(I)<=K;
type(index)=0;
else
type(index)=1;
end
for i=1:length(I)
if touched(I(i)) continue; end
touched(I(i))=1;
indices(end+1)=I(i);
class(I(i))=c;
end
end
indices=indices(2:end);
end
c=c+1;
end
end
I=find(class==0);
class(I)=-1;
type(I)=-1;
function d=epsilon(x,k)
[m,n]=size(x);
d=((prod(max(x)-min(x))*k*gamma(.5*n+1))/(m*sqrt(pi.^n))).^(1/n);
function D=distances(x,X)
D=sqrt(sum((ones(size(X, 1),1)*x-X).^2, 2));

Antworten (1)

Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran am 24 Mär. 2012
Hi, Please mail me at siva@sdatech.in.... mail me the exact .m code i could try and let you know.
Regards, Siva
  1 Kommentar
pdp rpa
pdp rpa am 25 Mär. 2012
thnks Siva. above i have already given the m file for dbscannew and also mailed u. plz help me

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by