【发布时间】:2017-01-08 18:46:36
【问题描述】:
我想练习一下matlab中的图形界面设计,这个图形界面有两个功能——一是选择图像,二是过滤,这种图形界面的总体结构非常简单
这里有两个代码 - 一个在按下选择图像后选择图像,第二个在单击过滤图像后使用简单平均过滤器过滤图像
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
为什么会这样?提前致谢
【问题讨论】:
-
image是 Matlab 中函数的名称,因此您可能会因为命名变量图像而发生冲突。尝试更改该变量的名称 -
有一个问题,从第二个函数我无法访问第一个函数中的变量,我的意思是违反了变量范围,所以我应该将它声明为全局吗?
-
我已经解决了,我会发布我的代码
标签: image matlab image-processing filter gui-designer