2017-01-08 5 views
0

내가 GUI를 MATLAB에서 GUI를 설계 연습하고 싶습니다,이 GUI는 두 가지 기능을 가지고 있습니다 - 하나의 이미지를 선택하고 필터링을위한 일반적인 구조는 그래픽 인터페이스는 매우 간단합니다
enter image description here이미지를 선택하고 필터링을위한 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); 

을 클릭 한 후 단순 평균 필터를 이용하여 이미지를 필터링 선택 이미지 및 제 눌러 후

012 필터링하기위한 이미지를 선택 개의 코드 온이고 내가 코드를 실행하면 3,516,
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 

왜 이런 오류

다음있어이 파일

enter image description here

을 간단한 선택? 미리 감사드립니다

+0

'image'가있다 Matlab의 함수 이름이므로 변수 이미지의 이름을 지정한 이후에 충돌이 발생할 수 있습니다. 해당 변수의 이름을 변경해보십시오 –

+0

두 번째 함수에서 첫 번째 함수에서 변수에 액세스 할 수없는 한 가지 문제가 있습니다. 변수 범위가 위반됨을 의미하므로 전역 변수로 선언해야합니까? –

+0

나는 해결했고 내 코드를 올릴 것이다. –

답변

0

내 질문에 따라 문제에 관련, 내 솔루션을 포함하기로 결정했습니다, 내가 연구 후 발견, 여기 내 코드의 조각입니다, @ Benoit_11 덕분에 그의 충고와 전 난 기능 된 GetImage를 사용하는 다른 함수를 형성한다 (이 경우 이미지에서) 하나 개의 변수 액세스에 대한 내 코멘트에 관련 selected_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'); 
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