如何解决此错误"Error using - Matrix dimensions must agree"



我会通过使用mean(template)找到图像的平均值,但它抛出了一个错误。
我该如何解决这个问题?

template = imread('template.bmp');
meanTemplate = mean(template);
sum1 = sum((template(1:66,1:32)-meanTemplate).^2);

图像template是一个矩阵,因此mean(template)是一个向量,因为平均值是沿着第一维计算的。如果要计算图像的整体平均值,则应首先将矩阵展平为向量,即 meanTemplate = mean(template(:)) .

不确定你到底想做什么,

但模板(1:m,1:n)的大小为n x m,平均模板为1 x n。MATLAB 应该如何计算差异?这完全没有意义。

顺便说一句...

template == template(1:m,1:n)

最新更新