菜肉包子 发表于 2006-4-15 14:25

这段代码出错拉~高手来帮忙看看~

<P>eval(['info=imfinfo(''',file, ''');']);<BR>switch info.ColorType<BR>    case 'truecolor'<BR>      eval(['RGB=imread(''',file, ''');']);<BR>%       = rgb2ind(RGB, 256);<BR>      I = rgb2gray(RGB);<BR>      clear RGB;<BR>    case 'indexed'<BR>      eval(['=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 ==&gt; 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>% <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>%       = rgb2ind(RGB, 256);<BR>      I = rgb2gray(RGB);<BR>      clear RGB;<BR>    case 'indexed'<BR>      eval(['=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>=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>

zjliu 发表于 2006-4-15 18:26

我看不到你的图片,但是这个语句你写的是不对的:<BR>eval(['info=imfinfo(''',file, ''');']);<BR>eval函数的输入一定得是一个正确语句对应的字符串,你改<BR>正确了这个就可以通过这个错误了

菜肉包子 发表于 2006-4-15 19:04

恩~我就是不晓得怎么改啊~<BR>这个代码我是从网上下的<BR>说是这个代码是做FCM的图象分割的<BR>我没有图片啊<BR>只是说我做的界面想要读入图片~<BR><BR>糊涂了

菜肉包子 发表于 2006-4-15 19:05

那这段源码~那这个是要单独写进M文件的的吗?就是说我还要再做个界面?然后调用这个?<BR>

菜肉包子 发表于 2006-4-15 19:12

<P>我就是不知道我具体要怎么做啊?<BR>现在我有段从网上下的代码,就是上面的,但是单独放EDIT里头运行会出错~<BR>我以为直接有这段代码就可以实现我的FCM图象分割了~请问是吗?<BR><BR>如果不是~是不是还要用GUIDE做个界面~然后把上面的代码单独弄个M,然后在GUI生成的M里头添些回调函数啥的,来调用来调用那个图象处理的M啊?<BR>我说的阿对啊?</P>

zjliu 发表于 2006-4-15 19:33

把文件名填进去

菜肉包子 发表于 2006-4-15 19:43

回复:(zjliu)把文件名填进去

<DIV class=quote><B>以下是引用<I>zjliu</I>在2006-4-15 19:33:43的发言:</B><BR>把文件名填进去</DIV>高手还能稍微说明白点啊~<BR>把文件名填哪啊?<BR>这个文件名是什么文件的啊?

zjliu 发表于 2006-4-15 19:46

as follows<BR>eval(['info=imfinfo(filename.bmp);']);<BR>

菜肉包子 发表于 2006-4-15 20:04

回复:(zjliu)as followseval(['info=imfinfo(filen...

<DIV class=quote><B>以下是引用<I>zjliu</I>在2006-4-15 19:46:19的发言:</B><BR>as follows<BR>eval(['info=imfinfo(filename.bmp);']);<BR></DIV>如那是不是还要用GUIDE做个界面~然后把上面的代码单独弄个M,然后在GUI生成的M里头添些回调函数啥的,来调用那个单独的M啊?<BR><BR>
<br>

菜肉包子 发表于 2006-4-15 22:14

顶上去

happy 发表于 2006-4-16 08:11

回复:(菜肉包子)这段代码出错拉~高手来帮忙看看~

你到底想做什么呢?能否先说清楚

xiaoyu1218 发表于 2008-12-24 09:30

这段程序没有错,我试过了,是一个被调用的函数,在命令窗口输入fcmapp('xx.bmp',3)就是结果了
页: [1]
查看完整版本: 这段代码出错拉~高手来帮忙看看~