Trouble with error from polyfit

3 ビュー (過去 30 日間)
Jonathan Patterson
Jonathan Patterson 2018 年 4 月 14 日
編集済み: John D'Errico 2018 年 4 月 14 日
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 Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by