MATLAB将地图转化为Graph,image – MATLAB如何将轴坐标转换为像素坐标?

请考虑以下代码.它显示了如何从轴坐标转换为图像像素坐标.

如果使用除默认1:width和1:height之外的自定义XData / YData位置绘制图像,此功能尤其有用.在下面的示例中,我在x / y方向上移动了100和200像素.

function imageExample()

%# RGB image

img = imread('peppers.png');

sz = size(img);

%# show image

hFig = figure();

hAx = axes();

image([1 sz(2)]+100, [1 sz(1)]+200, img) %# shifted XData/YData

%# hook-up mouse button-down event

set(hFig, 'WindowButtonDownFcn',@mouseDown)

function mouseDown(o,e)

%# get current point

p = get(hAx,'CurrentPoint');

p = p(1,1:2);

%# convert axes coordinates to image pixel coordinates

%# I am also rounding to integers

x = round( axes2pix(sz(2), [1 sz(2)], p(1)) );

y = round( axes2pix(sz(1), [1 sz(1)], p(2)) );

%# show (x,y) pixel in title

title( sprintf('image pixel = (%d,%d)',x,y) )

end

end

(注意轴限制不是从(1,1)开始,因此需要axis2pix)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值