Why the pixel position by currentpoint and getpixelposition are not same at same point?

1 次查看(过去 30 天)
I have image on an axis (axis1) in gui. I check the pixel positions of axes and check the currentpoint of mouse on the intial point of axis. The values comming from both variables are different. I execute following code. I think the first two values of pos1 and currentpoint value should be same at this point.
pos1 = getpixelposition(eventdata.axes1)
currentp=src.CurrentPoint
The output from this code is
pos1 =
1.0e+03 *
0.3887 0.5098 1.2986 0.5377
currentp =
6.6000 731.4000
The point selected is shown in the image. Later on I want to replace the values of x1,y1,x2,y2 with the position values to fill the if-else condition
x1=680;
y1=1046;
matlabImage = imread(strcat(num2str(randArr(3)),'.tif'));
[r,c,~]=size(matlabImage);
x2=1397;
y2=512;
if ((currentp(1)<x2&&currentp(1)>x1)&&currentp(2)>y2&&currentp(2)<y1)
% axes(hObject.figure1);
rectangle('Position', [-2,-2,c+4,r+4],'EdgeColor','r');
else
rectangle('Position', [-2,-2,c+4,r+4],'EdgeColor',[0,0,0]');
end
Untitled.png
  2 个评论
Adam
Adam 2019-1-11
编辑:Adam 2019-1-11
currentPoint is in whatever the units are of the component you call it on, whether that be the Figure or axes or whatever your src is. Unless these units are pixels you will get different answers.
Obviously if eventdata.axes1 is not the same as src then you will also get a different answer as it will be relative to a different origin.
Abdulllah
Abdulllah 2019-1-11
编辑:Abdulllah 2019-1-11
Thank you Adam, for your reply. So how can get the orignal pixel values i.e. absolute values? I spent hours to sort out this task even could not get solution on internet. How can I get those image values to draw the rectangle? All this code is in WindowButtonMotionFcn.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by