我知道应该有一个简单的(更快的!)我的Matlab索引问题的解决方案,但我的google-jutsu出现了不足,我无法解决它……:'(
我正在尝试使用Lanczos重采样/过滤/任何你想要的名称来对图像应用可塑性变形。
我需要从G获取对应于变形点(格式由meshgrid()返回,但随后变形)的图像样本,从源图像中进行插值。不幸的是,由于应用的变形(透明,平移,旋转,拉伸),G(a:b, a:b)将不再给出正确的样本范围…
G = imload('xxx');
[x,y] = meshgrid(a:b);
% Applies an arbitrary plastic deformation
% size(Qx) == size(x), size(Qy) == size(y)
[Qx, Qy] = f(x,y, deformation);
% This, There must be an easier way to do this!!!
% By the way: Qx, and Qy are doubles, hence the floor() and I need to do
% some other arithmetic too but that is irrelevant for now.
G_samples = arrayfun(@(X,Y) G(Y,X), floor(Qx), floor(Qy));我这里的主要问题是,这段代码在我的代码的绝对内部,时间关键的部分,我希望有一种比arrayfun更快的方式。上面这行代码大约占我执行时间的80%。
提前感谢!
编辑
@natan这不是这里的问题,我需要完成以下工作:
for y=a:b
for x=a:b
G_samples(y,x) = G(floor(Qx(x,y)), floor(Qy(x,y)));
end
end我有大约r2006a的ImageProcessing工具箱。
解决方案
不完全像我想要的那样漂亮,但速度更快:
P = impixel(G, floor(Qx), floor(Qy));
G_samples = reshape(P(;,1), size(Qx));发布于 2013-07-17 21:09:21
我找到了答案
P = impixel(G, floor(Qx), floor(Qy));
G_samples = reshape(P(;,1), size(Qx));(只需确保此问题已标记为已回答,以防有人遇到同样的问题)
https://stackoverflow.com/questions/17175914
复制相似问题