Azzera filtri
Azzera filtri

Polynomial Regression, camera RGB to CIE XYZ

4 visualizzazioni (ultimi 30 giorni)
Roger Breton
Roger Breton il 10 Mar 2021
Risposto: Gautam il 16 Feb 2024
I have two [24 x 3] matrices, one for fractionnal [0 to 1.0) RGB numbers and one for fractional (0 to 1.0) XYZ numbers.
I'd like to use Matlab to compute the Least Squares polynomial regression to relate these two sets of numbers.
My XYZ matrix looks like this :
XYZ_X XYZ_Y XYZ_Z
0.1167 0.1006 0.0499
0.3916 0.3048 0.0457
0.0687 0.0552 0.2 ...
My RGB matrix looks like this :
Ravg Gavg Bavg
0.0378033 0.047519 0.027234
0.1264551 0.107156 0.032512
0.0168213 0.0471 0.074999 ....
Most examples I find relate only two 1D sets of numbers like this :
x = [1 2 3 4 5.5 7 10]
y = [3 7 9 15 22 21 21]
And do a least squares fit this way :
p2 = polyfit(x, y, 2)
But I have 2 sets of 3D numbers?
I'm going in cirle because I can't figure how to pose the problem.
Any help is appreciated.

Risposte (1)

Gautam
Gautam il 16 Feb 2024
Hello, Roger
I understand that you have two matrices one representing "X","Y" and "Z" coordinate information and the other representing the corresponding "R", "G" and "B" outputs and you want to perform a Least Squares polynomial regression on this data.
To perform polynomial regression with three variables in MATLAB, you can use the fitlm function for linear regression models, which also supports polynomial terms.
Since you have three output variables, you would have to fit a separate polynomial model for each output variable.
The first step would be to creating the polynomial terms for your model. For a polynomial with degree 2, this would look like
features = [X.^2 Y.^2 Z.^2 X.*Y Y.*Z Z.*X X Y Z]; %X, Y and Z are assumed to be column vectors
The next step is to fit a separate model for each output variable using the same set of polynomial features.
mdl_R = fitlm(features, R);
mdl_G = fitlm(features, G);
mdl_B = fitlm(features, B);
After fitting the models, you can analyze the results, look at the coefficients, and evaluate the performance of each model.
The figure below shows the polynomial generated by the model to fit the data. It is challenging to generate a plot to visualize the performance of the model due to high dimensions of the input and output variables. Each figure below shows a plot corresponding to the outputs "R", "G" and "B", where the outputs are plotted varying the "X" and "Y" values, holding the value of "Z" constant at the mean value of "Z".
Plot for “mdl_R”
Plot for “mdl_G”
Plot for “mdl_B”
I have attached the links to “fitlm documentation along with other links on modelling and plotting below, for your reference:
  1. fitlm: https://www.mathworks.com/help/releases/R2021a/stats/fitlm.html?searchHighlight=fitlm&s_tid=doc_srchtitle
  2. LinearModel: For methods and properties related to LinearModel object https://www.mathworks.com/help/releases/R2021a/stats/linearmodel.html
  3. meshgrid: To create 2D and 3D grid co-ordinates https://www.mathworks.com/help/releases/R2021a/matlab/ref/meshgrid.html?searchHighlight=meshgrid&s_tid=doc_srchtitle
  4. surf: To plot a “surface plot” https://www.mathworks.com/help/releases/R2021a/matlab/ref/surf.html?searchHighlight=surf&s_tid=doc_srchtitle
Thank You,
Gautam Murthy

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by