Why this program by Jose Vicente Manjon-Herrera isn´t working for my image?

조회 수: 2 (최근 30일)
Veronika
Veronika 2017년 3월 23일
댓글: Veronika 2017년 3월 23일
Dear all,
I would like to use this code by Jose Vicente Manjon-Herrera:
function [mu,mask]=kmeans(ima,k)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% kmeans image segmentation
%
% Input:
% ima: grey color image
% k: Number of classes
% Output:
% mu: vector of class means
% mask: clasification image mask
%
% Author: Jose Vicente Manjon Herrera
% Email: jmanjon@fis.upv.es
% Date: 27-08-2005
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check image
ima = 'thorax-mdl.jpg';
ima=double(ima);
copy=ima; % make a copy
ima=ima(:); % vectorize ima
mi=min(ima); % deal with negative
ima=ima-mi+1; % and zero values
s=length(ima);
% create image histogram
m=max(ima)+1;
h=zeros(1,m);
hc=zeros(1,m);
for i=1:s
if(ima(i)>0) h(ima(i))=h(ima(i))+1;end;
end
ind=find(h);
hl=length(ind);
% initiate centroids
mu=(1:k)*m/(k+1);
% start process
while(true)
oldmu=mu;
% current classification
for i=1:hl
c=abs(ind(i)-mu);
cc=find(c==min(c));
hc(ind(i))=cc(1);
end
%recalculation of means
for i=1:k,
a=find(hc==i);
mu(i)=sum(a.*h(a))/sum(h(a));
end
if(mu==oldmu) break;end;
end
% calculate mask
s=size(copy);
mask=zeros(s);
for i=1:s(1),
for j=1:s(2),
c=abs(copy(i,j)-mu);
a=find(c==min(c));
mask(i,j)=a(1);
end
end
mu=mu+mi-1; % recover real range
but still I have this error:
Not enough input arguments.
Error in kmeans (line 43)
mu=(1:k)*m/(k+1);
I attach my original image. Can you advise me? Thank you for your answers.
  댓글 수: 2
Adam
Adam 2017년 3월 23일
What do you mean by 'this' code? All you have shown is an error that implies you are calling kmeans somewhere and with too few arguments. Attaching your image is not so helpful to solving an error, the code would be more useful. If the algorithm doesn't do what you want then maybe the image is useful, but for purely fixing an error we need code.
Veronika
Veronika 2017년 3월 23일
Sorry, I forgot, now it´s okay.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by