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

1 回表示 (過去 30 日間)
Abdulllah
Abdulllah 2019 年 1 月 11 日
編集済み: Abdulllah 2019 年 1 月 11 日
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by