2012-12-29 2 views
0

GUI에 문제가 있습니다. 내 여는 기능에서 내가 저장 한 이미지가 img_new 변수를 정의했습니다.MATLAB 가이드 축의 현재 이미지를 imwrite

내 GUI에는 두 개의 축이 있는데, 하나는 원본 이미지를 표시하고 다른 하나는 필터링 된 축을 표시합니다. 4 개의 라디오 버튼이있는 패널에 4 개의 필터가 있습니다. 그리고 각 코드의 끝에는 img_new = 라디오 버튼 필터를 통해 생성 된 이미지가 있습니다. 여기

일부 코드이다 :

% --- Executes when selected object is changed in uipanel3. 
function uipanel3_SelectionChangeFcn(hObject, eventdata, handles) 
handles.count = handles.count + 1; 

% Change filter orientation depending on which radiobutton is chosen 
switch get(eventdata.NewValue,'Tag') 
    case 'hte' 
     h_te = zeros(handles.rows, handles.colums); 

     # code of the filter... 

     axes(handles.axes2); 
     imshow(h_te); 

     handles.img_new = h_te; 

    case 'hc' 
     h_c = zeros(handles.rows, handles.colums); 

     # code of the filter... 


     axes(handles.axes2); 
     imshow(h_c); 

     handles.img_new = h_c; 

    case 'vlr' 
     v_lr = zeros(handles.rows, handles.colums); 

     # code of the filter... 


     axes(handles.axes2); 
     imshow(v_lr); 

     handles.img_new = v_lr; 

    case 'vc' 
     v_c = zeros(handles.rows, handles.colums); 

     # code of the filter... 

     axes(handles.axes2); 
     imshow(v_c); 

     handles.img_new = v_c; 

end 
guidata(hObject, handles) 

그리고 여기 imwrite 함수이다 : 여기

% -------------------------------------------------------------------- 
function save_img_ClickedCallback(hObject, ~, handles) 
% writing the new image 
imwrite(handles.img_new, strcat('filtered_image_', num2str(handles.count), '.png')); 
guidata(hObject, handles) 

axes1 일본어로 이미지를 얻기) 및 axes2 (필터링)

로 필터링 기능의
% --- Executes on button press in img2. 
function img2_Callback(hObject, ~, handles) 
% Read image 2 
img = imread('./coimbra_estadio.jpg'); 
handles.img_d = im2double(img); 

% image size 
size_img = size(handles.img_d); 
handles.colums = size_img(2); 
handles.rows = size_img(1); 

if rem(handles.rows,2) == 0 
    handles.row_0 = ((handles.rows/2)+1); 
else 
    handles.row_0 = ((handles.rows/2)+0.5); 
end 

if rem(handles.colums,2) == 0 
    handles.colum_0 = ((handles.colums/2)+1); 
else 
    handles.colum_0 = ((handles.colums/2)+0.5); 
end 

axes(handles.axes1); 
imshow(img); 

% Generate eventdata to call the radiobuttons function 
eventdata_new.EventName = 'SelectionChanged'; 
eventdata_new.OldValue = get(handles.uipanel3,'SelectedObject'); 
eventdata_new.NewValue = get(handles.uipanel3,'SelectedObject'); 

uipanel3_SelectionChangeFcn(handles.uipanel3, eventdata_new, handles); 
guidata(hObject, handles) 

ee, 결국 패널 기능을 호출하므로 이미지가로드되면 자동으로 필터링되고 axes2 이미지가 변경됩니다.

저장 기능을 호출 할 때 문제가 발생하여 이전 img_new을 저장합니다.

라디오 버튼을 변경하면 img_new이 새로 고쳐 지지만 변경하지 않으면 새로 고침되지 않습니다. 이미지를 로딩 할 때 자동으로 radiobuttons 패널의 기능을 호출해야합니다.

답변

2

img2_Callback의 끝에있는 guidata(hObject,handles);은 최종 핸들 상태로 최종 핸들 개체를 저장하므로 uipanel3_SelectionChangeFcn에서 이루어진 업데이트가 손실됩니다. 수동 eitehr handles = guidata(hObject,handles); 또는 handles=guidata(hObject); 을 넣어 uipannel3_SelectionChangeFcn를 호출 한 후 핸들을 업데이트해야합니다 (guidata 업데이트 핸들에 전화하는 것을 잊었다, 그에 대한 도움말을 참조하십시오), 또는 단순히 코드가 작은 경우 안전 (img2_callback의 끝에 행 guidata(hObject,handles);을 제거 나중에 변경하려고 할 때 uipannel3_SelectionChangeFcn 이후 핸들을 업데이트하는 것이 더 안전합니다 ...

+0

내가 말한대로 설치했지만 작동하지 않습니다. 오래된 것을 저장합니다. – SamuelNLP

+0

나는 그것을 잘못된 장소에 넣습니다. 감사합니다. 일했다. – SamuelNLP

관련 문제