Modifying impixelinfo to display 3d coordinates

1 次查看(过去 30 天)
I want to display real world image coordinates (imrealinfo function)when user move the mouse over the image.
I have to get the image pixel coordinates with impixelinfoval Then I know the real world coordinate of the left top position of the image (origin in image space) also the pixel width
My code is
X3d = realcor(1,1) + realcor(3,1)* X;
Y3d = realcor(2,1) + realcor(4,1)* Y;
Z3d = Zdata(X3d, Y3d);
% realcor contain real world coordinates of left top corner of the image, pixel width
% Zdata contain Z details
X, Y are the output of impixelinfoval function.
so my new function should get the output of impixelinfoval and then compute the 3d coordinates and when user move the mouse imrealinfo command should show the 3d real coordinates of that point.
Any suggestion please
  1 个评论
bes
bes 2012-7-19
My problems are 1. how assign impixelinfoval output to x and y to compute 3d coordinate 2. How to display 3d coordinate when cursor moves?
Is there any way to get the impixelinfoval outputs to [x y] array?

请先登录,再进行评论。

采纳的回答

Matt Kindig
Matt Kindig 2012-7-19
I don't believe that impixelinfo or impixelinfoval allows you to specify a custom callback, which is what you would need to do what you are intending.
However, it should be relatively straightforward to essentially implement your own imrealinfo() function that does what you want to do. Are you familiar with writing your own custom callback functions? One way to structure your code is something like this (this is just the skeleton of the code-- this hasn't been tested and should probably be expanded to include error checking, etc.).
function imrealinfo( himg, ZData, realcor)
% hfig is handle to your image
% ZData and realcor are your "real-world" info
hax = get(himg, 'parent'); %handle to axes
hfig = get(hax, 'parent'); %handle to figure
hu = uicontrol('Style','edit', 'String', 'X3d=0, Y3d=0, Z3d=0')
set(hfig, 'WindowButtonMotionFcn', @motioncb)
function motioncb(src,evnt)
cp = get(hax, 'CurrentPoint');
X = cp(1,1);
Y = cp(1,2);
X3d = realcor(1,1) + realcor(3,1)* X;
Y3d = realcor(2,1) + realcor(4,1)* Y;
Z3d = Zdata(X3d, Y3d);
set(hu, 'String', sprintf('X3d=%0.2f, Y3d=%0.2f, Z3d=%0.2f', X3d, Y3d, Z3d));
end
end

更多回答(1 个)

Walter Roberson
Walter Roberson 2012-7-19
Perhaps you could do this with datacursormode . It allows custom callbacks for information display.

Community Treasure Hunt

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

Start Hunting!

Translated by