image segmentation
조회 수: 1 (최근 30일)
이전 댓글 표시
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));
댓글 수: 0
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!