Trouble with error from polyfit

3 次查看(过去 30 天)
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.

采纳的回答

John D'Errico
John D'Errico 2018-4-14
编辑:John D'Errico 2018-4-14
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 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by