我打算在我的图像上使用matlab中的glmfit应用全局线性模型 .

使用glmfit时出错(第227行)X和Y中的观察数必须匹配 .

更改错误(第10行)b = glmfit(gchanel,trainingAns(:),'normal'); %二项式正常%根据训练查看模型的输出

以下是我的代码 .

image = imread('21.tif');           %Input Image
trainingAns = imread('21.gif');     % Ground Truth
gchanel = image(:,:,2);

%%  GLM
szG = size(gchanel);
b = glmfit(gchanel,trainingAns(:),'normal'); %binomial   normal% see the output of the model based on the training
featuresCTrain = glmval(b,gchanel,'logit');
CTrain = reshape(CTrain,szG(1:2));

features = reshape(gchanel,[prod(szG(1:2)),1]);

我知道X和Y是什么 . X是我必须做预测的矩阵,Y是真实图像上的响应向量(在我的例子中是trainingAns) . 请帮我解决这个错误 . 以下是基础事实'21 .gif'的附图 . 在此处输入图像描述

enter image description here