필터 지우기
필터 지우기

i have found this code over internet.But i need its output coordinates in x and y variables. How i can do that ?

조회 수: 2 (최근 30일)
function [ x1,y1,x2,y2 ] = image_Coordinates
clc;clear;
imObj = imread('Finalized_Lhr_maps_Half.jpg');
figure;
hAxes = axes();
imageHandle = imshow(imObj);
set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
function ImageClickCallback ( objectHandle , eventData )
axesHandle = get(objectHandle,'Parent');
coordinates = get(axesHandle,'CurrentPoint');
coordinates = coordinates(1,1:2)
message = sprintf('x: %.1f , y: %.1f',coordinates (1) ,coordinates (2));
helpdlg(message);
end
% ah = get( imageHandle, 'Parent' );
% p = get( ah, 'CurrentPoint' )
end

답변 (2개)

Walter Roberson
Walter Roberson 2016년 4월 28일
[x(1), y(1), x(2), y(2)] = image_Coordinates();
  댓글 수: 4
Stephen23
Stephen23 2016년 4월 29일
편집: Stephen23 2016년 4월 29일
You need to allocate values to x1,y1,x2,y2 inside the function. MATLAB does not just invent some values for these: if you do not define inside the function what value x1 has, then what value do you expect the x1 output variable to have?
function out = myFun()
out = 4; % define the output variable
end

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2016년 4월 29일
I suggest you just learn how to use impixelinfo(). It's better because it gives you a "live" readout as you move the cursor over the image. No clicking even needed at all.
If you need to get the values into variables for use in your code, then I suggest you have a mode where the user does that, like a button where the button callback calls ginput(1). But if it's just for visual inspection, then I recommend impixelinfo().

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by