创建用于选择和过滤Image的GUI

时间:2017-01-08 18:46:36

标签: image matlab image-processing filter gui-designer

我想在matlab中设计GUI,这个GUI有两个功能 - 一个用于选择图像,另一个用于过滤,这种图形界面的一般结构非常简单
enter image description here

这里有两个代码 - 一个按下选择图像后选择图像,另一个代码在点击滤镜图像后使用简单平均滤镜过滤图像

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);

但是当我运行代码时,我选择了简单的这个文件

enter image description here

我收到了以下错误

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

为什么会这样?提前谢谢

1 个答案:

答案 0 :(得分:0)

基于我的问题并且与问题相关,我决定也包括我的解决方案,我在研究后发现,这里是我的代码的片段,首先感谢@ Benoit_11的建议,我已经更改了名称图像到selected_image,与我关于访问一个变量的注释(在本例中是图像)形成另一个函数我使用函数getimage,所以有我的完整解决方案

<p><a id="myAnchor" href="#part2">Click to move</a></p>

enter image description here