1

我知道我的 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));
4

1 回答 1

0

我找到了答案

P = impixel(G, floor(Qx), floor(Qy));
G_samples = reshape(P(;,1), size(Qx));

(只要确保这个问题被标记为已回答,以防有人遇到同样的问题)

于 2013-07-17T13:09:21.087 回答