Why the pixel position by currentpoint and getpixelposition are not same at same point?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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&¤tp(1)>x1)&¤tp(2)>y2&¤tp(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
2 comentarios
Adam
el 11 de En. de 2019
Editada: Adam
el 11 de En. de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks 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!