Trouble with error from polyfit

5 vues (au cours des 30 derniers jours)
Jonathan Patterson
Jonathan Patterson le 14 Avr 2018
Modifié(e) : John D'Errico le 14 Avr 2018
I have written Matlab code to perform the following steps:
1) Read the original cottage picture.
2) Obtain its sizes.
3) Show the x values for the curve fitting.
4) Make a copy of the original picture.
5) Iterate through top 70 rows where the sky is. Use functions polyfit and .
6) Iterate through each color individually.
7) The polynomial approximation needs each row as a double vector.
8) Compute a synthetic row.
9) Put the row into the new sky.
10) End the loops
11) Show the new image.
12) Show the old image.
Here is the code:
function imageManip(imageName)
inputImage = imread(imageName);
[sizeX,sizeY,~] = size(inputImage);
copyImage = inputImage;
for r = 1:70
for co = 1:3
var1 = 1:sizeY;
var2 = copyImage(r,:,co);
P = polyfit(var1,var2,2);
Y = polyval(P,var1);
copyImage(r,:,co) = Y;
end
end
imshow(copyImage);
end
When I run the code, the following errors appear:
Error using polyfit (line 68)
MTIMES (*) is not fully supported for integer classes. At least one argument must be
scalar.
Error in project2_1 (line 10)
P = polyfit(var1,var2,2);
Can someone explain how I can fix this? Thanks.

Réponse acceptée

John D'Errico
John D'Errico le 14 Avr 2018
Modifié(e) : John D'Errico le 14 Avr 2018
The pixels in an image are stored as uint8 (apparently in this case). Is that not what the error message effectively told you?
Convert to doubles to use polyfit.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by