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