2012-07-02 49 views
2

我試圖加載圖像,但它顯示錯誤消息Undefined function or method 'readimage' for input arguments of type 'char'.未定義的函數或方法「readimage」類型「字符」

我調用的函數是在這裏

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新手。謝謝。

+1

有一個在MATLAB沒有名爲readimage功能。你有沒有定義你自己的?或者你可以嘗試使用[imread](http://www.mathworks.se/help/techdoc/ref/imread.html)。 –

+0

謝謝。我的readimage函數就像函數b = readimage(w) a = imread(w); b = double(a); ' – Kabir

+0

請在Matlab命令窗口運行'which readimage'來檢查路徑上是否可見該函數。如果沒有,請將目錄更改爲存儲了readimage的任何位置,或將該目錄添加到路徑中(在菜單文件中)。 – Jonas

回答

2

我可以重現這隻作爲一個路徑問題。

問題幾乎可以確定,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(路徑名)來更改目錄,而是將它合併到readimage命令本身中。

我敢打賭,cd()命令和它不在路徑上的組合讓你認爲readimage(w)是在路徑上工作,當它真的只在當前目錄中...直到運行cd()命令。

0

的功能有輕微的改寫:

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 
相關問題