bsxfun 的理解

  • (1) 第一个参数是二元算子

  • (2) 执行的逐元素(element-wise)的运算

  • (3) 如果是一个行向量和一个矩阵进行二元运算,则会首先把行向量broadcast(广播、扩散)直至和矩阵的维度匹配。同理,一个列向量和一个矩阵二元运算也是如此。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
[max_resp_row, max_row] = max(response, [], 1); [init_max_response, max_col] = max(max_resp_row, [], 2); max_row_perm = permute(max_row, [2 3 1]); col = max_col(:)'; row = max_row_perm(sub2ind(size(max_row_perm), col, 1:size(response,3))); trans_row = mod(row - 1 + floor((use_sz(1)-1)/2), use_sz(1)) - floor((use_sz(1)-1)/2); trans_col = mod(col - 1 + floor((use_sz(2)-1)/2), use_sz(2)) - floor((use_sz(2)-1)/2); init_pos_y = permute(2pi * trans_row / use_sz(1), [1 3 2]); init_pos_x = permute(2pi * trans_col / use_sz(2), [1 3 2]); max_pos_y = init_pos_y; max_pos_x = init_pos_x; % pre-compute complex exponential exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); % gradient_step_size = gradient_step_size / prod(use_sz); ky2 = ky.ky; kx2 = kx.kx; iter = 1; while iter <= iterations % Compute gradient ky_exp_ky = bsxfun(@times, ky, exp_iky); kx_exp_kx = bsxfun(@times, kx, exp_ikx); y_resp = mtimesx(exp_iky, responsef, 'speed'); resp_x = mtimesx(responsef, exp_ikx, 'speed'); grad_y = -imag(mtimesx(ky_exp_ky, resp_x, 'speed')); grad_x = -imag(mtimesx(y_resp, kx_exp_kx, 'speed')); ival = 1i * mtimesx(exp_iky, resp_x, 'speed'); H_yy = real(-mtimesx(bsxfun(@times, ky2, exp_iky), resp_x, 'speed') + ival); H_xx = real(-mtimesx(y_resp, bsxfun(@times, kx2, exp_ikx), 'speed') + ival); H_xy = real(-mtimesx(ky_exp_ky, mtimesx(responsef, kx_exp_kx, 'speed'), 'speed')); det_H = H_yy . H_xx - H_xy . H_xy; % Compute new position using newtons method max_pos_y = max_pos_y - (H_xx .* grad_y - H_xy .* grad_x) ./ det_H; max_pos_x = max_pos_x - (H_yy .* grad_x - H_xy .* grad_y) ./ det_H; % Evaluate maximum exp_iky = exp(bsxfun(@times, 1i * ky, max_pos_y)); exp_ikx = exp(bsxfun(@times, 1i * kx, max_pos_x)); iter = iter + 1; end max_response = 1 / prod(use_sz) * real(mtimesx(mtimesx(exp_iky, responsef, 'speed'), exp_ikx, 'speed')); % check for scales that have not increased in score ind = max_response < init_max_response; max_response(ind) = init_max_response(ind); max_pos_y(ind) = init_pos_y(ind); max_pos_x(ind) = init_pos_x(ind); [max_scale_response, sind] = max(max_response(:)); disp_row = (mod(max_pos_y(1,1,sind) + pi, 2pi) - pi) / (2pi) * use_sz(1); disp_col = (mod(max_pos_x(1,1,sind) + pi, 2pi) - pi) / (2pi) * use_sz(2); end代码详解
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五道口纳什

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值