【问题标题】:Undefined function or method 'readimage' for input arguments of type 'char''char' 类型的输入参数的未定义函数或方法 'readimage'
【发布时间】:2012-07-02 23:21:03
【问题描述】:

我正在尝试加载图像,但它显示错误消息Undefined function or method 'readimage' for input arguments of type 'char'.

我的调用函数在这里

 h=uicontrol(FigWin,...
 'Style','pushbutton',...
 'Position',[0,320,80,20],...
 'String','Load',...
 'Callback',...
 ['image1=loadimage;'...
 'subplot(AxesHandle1);'...
 'imagesc(image1);'...
 'title(textLoad);'...
 'colormap(gray);']);

我调用的函数在下面

function image1=loadimage
    [imagefile1 , pathname]= uigetfile('*.bmp;*.BMP;*.tif;*.TIF;*.jpg','Open An Fingerprint image'); 
    if imagefile1 ~= 0 
        cd(pathname);
        image1=readimage(char(imagefile1));
        image1=255-double(image1);
    end
end

另一个问题,如果程序中有警告,是不是有问题?对不起,我是 Matlab 的新手。谢谢你。

【问题讨论】:

  • MATLAB 中没有名为 readimage 的函数。你定义了自己的吗?或者您可以尝试改用imread
  • 谢谢。我的 readimage 函数就像function b = readimage(w) a=imread(w); b = double(a);
  • 请在Matlab命令窗口中运行which readimage检查函数在路径上是否可见。如果没有,请将目录更改为您存储 readimage 的位置,或将该目录添加到路径(在菜单文件中)。

标签: matlab


【解决方案1】:

我只能将其重现为路径问题。

问题几乎可以肯定是readimage.m 不在路径上,而是位于您测试它的当前目录中。现在最简单的解决方案是直接使用imread,而不是直接使用包装器readimage,但假设您想稍后向readimage 添加功能:

简单的解决方案是将目录readimage.m 添加到您的路径(文件->设置路径->添加文件夹->使用 readimage.m 浏览到目录)。但是,如果您想测试这确实是问题所在,请确保您可以手动运行readimage('existing_image.jpg')(意味着您应该浏览到该目录),然后运行以下修改后的代码

function image1=loadimage
    [imagefile1 , pathname]= uigetfile('*.bmp;*.BMP;*.tif;*.TIF;*.jpg','Open An Fingerprint image'); 
    if imagefile1 ~= 0 
        image1=readimage([pathname imagefile1]);
        image1=255-double(image1);
end;

与原始代码的唯一区别是我们没有使用 cd(pathname) 来更改目录,而是将其合并到 readimage 命令本身中。

我打赌 cd() 命令和它不在路径上的组合使您认为 readimage(w) 在路径上并且正在工作,而它实际上只是在当前目录中。 .. 直到运行 cd() 命令。

【讨论】:

    【解决方案2】:

    稍微重写你的函数:

    function img = loadimage()
        [fname,pname] = uigetfile('*.bmp;*.tif;*.jpg', 'Open Fingerprint image');
        if pname==0, error('no file selected'); end
    
        img = imread( fullfile(pname,fname) );
        img = 255 - double(img);
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多