我想在matlab中设计GUI,这个GUI有两个功能 - 一个用于选择图像,另一个用于过滤,这种图形界面的一般结构非常简单
这里有两个代码 - 一个按下选择图像后选择图像,另一个代码在点击滤镜图像后使用简单平均滤镜过滤图像
function select_image_Callback(hObject, eventdata, handles)
% hObject handle to select_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.jpg';'*.png'},'File select');
image=strcat(pathname,filename);
axes(handles.axes1);
imshow(image);
和过滤
function filter_image_Callback(hObject, eventdata, handles)
% hObject handle to filter_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = ones(5,5) / 25;
Filtered_image = imfilter(image,h);
axes(handles.axes2);
imshow(Filtered_image);
但是当我运行代码时,我选择了简单的这个文件
我收到了以下错误
Error using imfilter
Expected input number 1, A, to be one of these types:
numeric, logical
Instead its type was matlab.graphics.primitive.Image.
Error in imfilter>parse_inputs (line 186)
validateattributes(a,{'numeric' 'logical'},{'nonsparse'},mfilename,'A',1);
Error in imfilter (line 118)
[a, h, boundary, sameSize, convMode] = parse_inputs(varargin{:});
Error in filter_image_filter_image_Callback (line 92)
Filtered_image = imfilter(image,h);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in filter_image (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)filter_image('filter_image_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
为什么会这样?提前谢谢