create GUI for selecting and filtering of Image

492 Views Asked by At

i would like to practice on designing GUI in matlab ,this GUI has two function -one for selecting of image and second for filtering,general structure of such Graphical interface is very simple
enter image description here

and here is two code -one which select image after pressing on select image and second which filters image using simple average filter after clicking on filter image

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

and for filtering

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

but when i run code, i selected simple this file

enter image description here

i got following error

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

why happens this? thanks in advance

1

There are 1 best solutions below

0
On

based on my question and related to problem, i have decided to include my solution as well ,which i found after researching, here is fragments of my code, first of thanks to @ Benoit_11 for his advice and i have changed name from image to selected_image, related to my comment about accessing one variable(in this case image) form another function i used function getimage, so there is my complete solution

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');
selected_image=strcat(pathname,filename);
axes(handles.axes1);
imshow(selected_image);

% --- Executes on button press in filter_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)
selected_image=getimage(handles.axes1);
h = ones(5,5) / 25;
Filtered_image = imfilter(selected_image,h);
axes(handles.axes2);
imshow(Filtered_image);

enter image description here