加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
get_subwindow.m 806 Bytes
一键复制 编辑 原始数据 按行查看 历史
dongqiaqia 提交于 2017-06-20 20:00 . fisrt commit
function out = get_subwindow(im, pos, sz)
%GET_SUBWINDOW Obtain sub-window from image, with replication-padding.
% Returns sub-window of image IM centered at POS ([y, x] coordinates),
% with size SZ ([height, width]). If any pixels are outside of the image,
% they will replicate the values at the borders.
%
% Joao F. Henriques, 2014
% http://www.isr.uc.pt/~henriques/
if isscalar(sz), %square sub-window
sz = [sz, sz];
end
xs = floor(pos(2)) + (1:sz(2)) - floor(sz(2)/2);
ys = floor(pos(1)) + (1:sz(1)) - floor(sz(1)/2);
%check for out-of-bounds coordinates, and set them to the values at
%the borders
xs(xs < 1) = 1;
ys(ys < 1) = 1;
xs(xs > size(im,2)) = size(im,2);
ys(ys > size(im,1)) = size(im,1);
%extract image
out = im(ys, xs, :);
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化