Matlab:使用meshgrid()矩阵进行子矩阵选择

时间:2013-06-18 18:10:00

标签: matlab indexing

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

1 个答案:

答案 0 :(得分:0)

我找到了答案

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

(只是确保这个问题被标记为已回答,但有些人有同样的问题)