马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
<P>eval(['info=imfinfo(''',file, ''');']);<BR>switch info.ColorType<BR> case 'truecolor'<BR> eval(['RGB=imread(''',file, ''');']);<BR>% [X, map] = rgb2ind(RGB, 256);<BR> I = rgb2gray(RGB);<BR> clear RGB;<BR> case 'indexed'<BR> eval(['[X, map]=imread(''',file, ''');']);<BR> I = ind2gray(X, map);<BR> clear X;<BR> case 'grayscale'<BR> eval(['I=imread(''',file, ''');']);<BR>end;<BR><BR>错误提示:<BR>Error in ==> fcmapp at 9<BR>eval(['info=imfinfo(''',file, ''');']);<BR>我做的是基与FCM模糊聚类的图象分割~上面的代码是读入图象,怎么错了啊?<BR>整个代码如下:<BR>function fcmapp(file, cluster_n)<BR>% FCMAPP<BR>% fcmapp(file, cluter_n) segments a image named file using the algorithm<BR>% FCM.<BR>% [in]<BR>% file: the path of the image to be clustered.<BR>% cluster_n: the number of cluster for FCM.</P>
<P>eval(['info=imfinfo(''',file, ''');']);<BR>switch info.ColorType<BR> case 'truecolor'<BR> eval(['RGB=imread(''',file, ''');']);<BR>% [X, map] = rgb2ind(RGB, 256);<BR> I = rgb2gray(RGB);<BR> clear RGB;<BR> case 'indexed'<BR> eval(['[X, map]=imread(''',file, ''');']);<BR> I = ind2gray(X, map);<BR> clear X;<BR> case 'grayscale'<BR> eval(['I=imread(''',file, ''');']);<BR>end;<BR>I = im2double(I);<BR>filename = file(1 : find(file=='.')-1);<BR>data = reshape(I, numel(I), 1);</P>
<P>tic<BR>[center, U, obj_fcn]=fcm(data, cluster_n);<BR>elapsedtime = toc;</P>
<P>%eval(['save(', filename, int2str(cluster_n),'.mat'', ''center'', ''U'', ''obj_fcn'', ''elapsedtime'');']);<BR>fprintf('elapsedtime = %d', elapsedtime);</P>
<P>maxU=max(U);<BR>temp = sort(center, 'ascend');<BR>for n = 1:cluster_n;<BR> eval(['cluster',int2str(n), '_index = find(U(', int2str(n), ',:) == maxU);']);<BR> index = find(temp == center(n));<BR> switch index<BR> case 1<BR> color_class = 0;<BR> case cluster_n<BR> color_class = 255;<BR> otherwise<BR> color_class = fix(255*(index-1)/(cluster_n-1));<BR> end<BR> eval(['I(cluster',int2str(n), '_index(:))=', int2str(color_class),';']);<BR>end;<BR>filename = file(1:find(file=='.')-1);<BR>I = mat2gray(I);<BR>%eval(['imwrite(I,', filename,'_seg', int2str(cluster_n), '.bmp'');']);<BR>imwrite(I, 'temp\tu2_4.bmp');<BR>imview(I);</P>
<P>请高手指点啊<BR></P> |