在MatLab中,我們用GUI時,有時候需要導入mat格式的圖片,但是在GUI中調用load和在命令行里調用load不一樣,在命令行里調用load('im.mat'),加載進去是uint8的矩陣,但是我們在GUI中寫代碼加進去,默認得到的是一個struct結構體,如果我們此時強行用imshow來顯示導入的數據,會出現如下錯誤:
??? Error using ==> iptcheckinput
Function IMAGEDISPLAYVALIDATEPARAMS expected its first input, I,
to be one of these types:
double, single, uint8, uint16, uint32, int8, int16, int32, logical
Instead its type was struct.
為了取出其中的圖片數據,可浪費了我好幾個小時候,終於找到了方法,這樣我們就可以在GUI中的axes中顯示出圖片了,參見如下:
% Load im.mat filename = uigetfile('*.mat'); img = cell2mat(struct2cell(load(filename)));
axes(handles.axes_1);
imshow(img);