MATLAB Answers

Zoe
0

How to predict each pixel of image using regression model?

Asked by Zoe
on 7 Jul 2017
Latest activity Commented on by Noor Abbas on 19 Mar 2018
I have the following code that loops over each pixel of a .tif image to predict responses using ensemble of regression models.
X is a 753*6 numeric array which has 6 variables (also columns), and 753 rows. NR = 1380, NC = 1464.
I understand the error's meaning (The dimensions on both sides do not match each other), but I really do not know how to fix it. I imagine the result I need should be a 1380*1464 numeric array.
a = imread('LE71250521999276_b1.tif')
[NR,NC] = size(a);
Yfit = zeros(NR,NC);
for i = 1:NR
for j = 1:NC
Yfit(i,j) = predict(Mdl1999276,X);
end
end
ERROR: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Thank you for helping!!

  1 Comment

Your Mdl11999276 variable is undefined

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 7 Jul 2017
 Accepted Answer

Why are you using all of X to do the prediction each time?
Why are you reading in the image if you are not going to predict based on its values?
Ensembles often make one prediction per ensemble member per sample; if so then you might need to analyze a vector of results to decide what one output you want.
Predictions sometimes output a probability per class rather than a single class number.

  4 Comments

Show 1 older comment
Thank both of you for answering my question! (a is a grey-scale tiff image, so I guess my old code would be fine?)
The training sample i used to train my ensemble regression model has 6 predictor variables, so that the testing sample (X in the code) should also be a 6-column matrix or table. These 6 variables are DN values of different bands. Therefore I think the predictors and the image itself are related somehow.
I also tried this following code (changed a bit), the for loop DID work, but it returned me a 753*1 numeric array (same # of rows to the X input), but not a NR*NC array of predicted values that I expected. So the problem is how can I get a NR*NC array of predicted Y value then? Thank you again!
for i = 1:NR
for j = 1:NC
Yfit = predict(Mdl1999276,X); % I deleted (i,j)
end
end
Given any one pixel, do you need the full 753*6 X array to predict for it?
I suspect that you already built the knowledge in X into Mdl1999276 and should not be passing it in. I suspect you should be using
for j = 1 : NC
Yfit(:,j) = predict(Mdl1999276, a(:,j));
end
or something similar.
Does any paper or research that relevant with predict number of pixel using machine learning, Best Regards,

Sign in to comment.