Trouble with error from polyfit
2 views (last 30 days)
Show older comments
Jonathan Patterson
on 14 Apr 2018
Edited: John D'Errico
on 14 Apr 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.
0 Comments
Accepted Answer
John D'Errico
on 14 Apr 2018
Edited: John D'Errico
on 14 Apr 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.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!