Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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

Respuestas (2)

Walter Roberson
Walter Roberson el 28 de Abr. de 2016
[x(1), y(1), x(2), y(2)] = image_Coordinates();
  4 comentarios
Stephen23
Stephen23 el 29 de Abr. de 2016
Editada: Stephen23 el 29 de Abr. de 2016
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

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 29 de Abr. de 2016
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().

Categorías

Más información sobre Computer Vision with Simulink en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by