Matlab中的此功能是什么?
问题描述:
有人可以详细告诉我此功能的每一行是什么吗?
Can someone tell me in detail what each line does of this function?
function [out]=Compare(SampleImage,DatabaseImage)
nCol=(3+1+2);
colourN=[];textureN=[];positionN=[];
for times=1:size(DatabaseImage,2)/nCol
sp=nCol*(times-1);
colourN = [colourN norm(SampleImage(:,1:3)-DatabaseImage(:,sp+1:sp+3))];
textureN=[textureN norm(SampleImage(:,4)-DatabaseImage(:,sp+4))];
positionN=[positionN norm(SampleImage(:,5:6)-DatabaseImage(:,sp+5:sp+6))];
end
out=[colourN;textureN;positionN];
谢谢.
答
所以我想我也已经弄清楚了.看起来图像被表示为6个矢量,其中包含颜色,纹理和位置数据.因此,样本图像的输入是一个表示图像的Mx6数组. DatabaseImage包含许多这些矢量表示形式
So I think I've figured this one out as well. It would appear that the images are represented as 6 vectors which hold color, texture and position data. So the input of sample image is an Mx6 array which represents an image. The DatabaseImage holds a number of these vector representations
function [out]=Compare(SampleImage,DatabaseImage)
% //define the 6 columns, and initialize some empty arrays
nCol=(3+1+2); % //input appears to be a 6 band vector image ie Mx6
colourN=[];textureN=[];positionN=[];
% //for 1 to number of cols in DatabaseImage / nCol
% //This will be the number of images in DatabaseImage.
% //so this loop loops over each database vector image
for times=1:size(DatabaseImage,2)/nCol
% //zero-based index of the first column of the current image
sp=nCol*(times-1);
% //this will be the "distance" between the two values in terms of color, texture and position
% //append each of these to the end of the array.
colourN = [colourN norm(SampleImage(:,1:3)-DatabaseImage(:,sp+1:sp+3))];
textureN=[textureN norm(SampleImage(:,4)-DatabaseImage(:,sp+4))];
positionN=[positionN norm(SampleImage(:,5:6)-DatabaseImage(:,sp+5:sp+6))];
end
% // then append along the other dimension to output as one matrix
out=[colourN;textureN;positionN];