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&¤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 个评论
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!