cell作为normxcorr2的输入参数

时间:2017-04-20 13:23:59

标签: matlab cells

我想计算具有大量模板(31个模板)的图像的规范化互相关。当我将模板定义为单元格并编译时:

parfor ii =1 :100
for j= 25:55
  % T {ii,j}=normxcorr2(template{j} ,image{ii});
end
end

它返回一个错误,因为normxcorr2的输入不能是单元格(只有矩阵)。我当然可以使用for循环:

{{1}}

但是它会花费更多时间(因为嵌套循环)。

我的问题是,如果有一个解决方案,以便不使用嵌套循环。

1 个答案:

答案 0 :(得分:0)

可能会将您的模板重新安排在单元格数组中,然后应用normxcorr2作为cellfun可以帮助您:

% generate random image and templates
image = rand(100);
% templates of 5X5
templates = rand(5,5,31);
% convert templates into cell array
templates = squeeze(mat2cell(templates,size(templates,1),...
    size(templates,2),ones(1,size(templates,3))));
% apply cellfun
T = cellfun(@(t) normxcorr2(t ,image),templates,'UniformOutput',0);

请注意,如果您的模板未在单元格数组中提供且模板的大小不相等(此处为5X5),则您需要以不同的方式创建templates单元格数组(仍然虽然简单。)