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

1 vue (au cours des 30 derniers jours)
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 commentaires
Adam
Adam le 11 Jan 2019
Modifié(e) : Adam le 11 Jan 2019
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 le 11 Jan 2019
Modifié(e) : Abdulllah le 11 Jan 2019
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by