马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
<P>帮帮我啊~在某网上下的源码~说是FCM的图象分割~可以分割,灰度图,索引图,彩图<BR>可是程序会在报错,在eval那~是不是要在这''',file, '''输入图象的名称啊?不懂啊~<BR>我是菜鸟!<BR><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.<BR><BR>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);<BR><BR>tic<BR>[center, U, obj_fcn]=fcm(data, cluster_n);<BR>elapsedtime = toc;<BR><BR>%eval(['save(', filename, int2str(cluster_n),'.mat'', ''center'', ''U'', ''obj_fcn'', ''elapsedtime'');']);<BR>fprintf('elapsedtime = %d', elapsedtime);<BR><BR>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);<BR></P> |