2017-04-07 2 views
1

두 개의 축에 두 개의 이미지가있는 예제 GUI 코드를 첨부하고 ginput을 사용하여 시드 포인트를 선택하면 어느 축에서나 선택할 수 있습니다. Is 어쨌든, 특정 축시드 포인트를 선택하기 위해 현재 축으로 제한하는 방법

% --- Executes on button press in open. 
function open_Callback(hObject, eventdata, handles) 
% hObject handle to open (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
global img1; 
global img2; 

img1 = imread('peppers.png'); 
img2 = imread('rice.png'); 

axes(handles.axes1); 
imshow(img1,[]); 
axes(handles.axes2); 
imshow(img2,[]); 


% --- Executes on button press in seedpointSelect. 
function seedpointSelect_Callback(hObject, eventdata, handles) 
% hObject handle to seedpointSelect (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
global img1; 
global img2; 
global x; 
global y; 

axes(handles.axes1); 
imshow(img1,[]); 
[y,x] = ginput(handles.axes1); 
y = round(y); x = round(x); 
set(handles.xcord,'String',num2str(x)); 
set(handles.ycord,'String',num2str(y)); 

특정 축에 ginput 제한에 어떤 도움을

감사합니다, Gopi

답변

0

ginput를 사용하지 마십시오을 ginput을 제한 마우스 클릭 콜백을 만들 수 있습니다 대신 (ButtonDownFcn). 예를 들어 축에서 콜백 함수를 제거하도록 콜백을 설정할 수 있습니다. 콜백을 설정하는 주 프로그램에서이 속성을 변경하려면 waitfor 속성을 사용합니다. 사용자가 클릭하자 마자 제어권이 다시 생겨 마지막 마우스 클릭 위치 (CurrentPoint)를 읽을 수 있습니다. 읽은 위치는 화면 좌표가 아닌 축 좌표입니다. 이것은 좋은 일로, 표시된 이미지의 픽셀에 해당 할 가능성이 큽니다. MATLAB의 이전 버전에서

0

당신은 더 나은 접근 방식은 비록 당신이 더 많은 제어권을 가지고 ButtonDownFcn을 사용하는 것입니다 ginput

set(handles.axes2, 'Hittest', 'off') 

에서 클릭을 무시하도록 axesHitTest 속성을 변경할 수 있도록 사용 axes 개체가있는 마우스 이벤트. 당신의 OpeningFcn

set(handles.axes1, 'ButtonDownFcn', @mouseCallback) 

내에서

그런 다음 콜백 함수

function mouseCallback(src, evnt) 
    handles = guidata(src); 

    % Get the current point 
    xyz = get(src, 'CurrentPoint'); 

    x = xyz(1,1); 
    y = xyz(1,2); 

    % Store x/y here or whatever you need to do 
end 
을 만들어야합니다
관련 문제