怎么用matlab画多项式拟合函数图像-数字图像处理matlab实验图像增强-_1( 二 )


3、将img原图像的大小(长、宽、通道数)赋值给row、co、ch,并以此设置放大图像大小
[row,col,ch] = size(img);
large = zeros(size(img));
4、在large放大图像中进行三重for循环拟合所有的未定义像素点
for c=1:ch
for y=5:col-5
for x=5:row-532
large(x,y,c) = mypoly(x,y,c,small);
end
end
end
5、幕布并输出large图像
figure
large = mat2gray(large);
large = uint8(large*255);
imshow(large),title('拟合放大图像')
6、自定义函数像素赋值函数mypoly的定义
function value = https://www.08ts.cn/mypoly(x,y,c,small)
small_x = floor((x+1)/2);
small_y = floor((y+1)/2);
if small_x==(x+1)/2 && small_y==(y+1)/2
value = https://www.08ts.cn/small(small_x,small_y,c);
return;
end
f1=int32(0);
f2=int32(0);
f3=int32(0);
f4=int32(0);
f5=int32(0);
f6=int32(0);
for localx=-2:1:2
for localy=-2:1:2
f1=f1+int32(localx^2*int32(small(uint32(small_x+localx),uint32(small_y+localy),c)));
f2=f2+int32(localy^2*int32(small(uint32(small_x+localx),uint32(small_y+localy),c)));
f3=f3+int32(localx*localy*int32(small(uint32(small_x+localx),uint32(small_y+localy),c)));
f4=f4+int32(localx*int32(small(uint32(small_x+localx),uint32(small_y+localy),c)));
f5=f5+int32(localy*int32(small(uint32(small_x+localx),uint32(small_y+localy),c)));
f6=f6+int32(small(uint32(small_x+localx),uint32(small_y+localy),c));
end
end
A = [170 100 0 0 0 50;100 170 0 0 0 50;0 0 100 0 0 0;0 0 0 50 0 0;0 0 0 0 50 0;50 50 0 0 0 25];
D = [double(f1);double(f2);double(f3);double(f4);double(f5);double(f6)];
C = A\D;
a = C(1,1);
b = C(2,1);
c1 = C(3,1);
d = C(4,1);
e = C(5,1);
h = C(6,1);
if small_x<(x+1)/2 && small_y==(y+1)/2
value = https://www.08ts.cn/a/4-d/2+h;
return;
end
if small_x==(x+1)/2 && small_y<(y+1)/2
value = https://www.08ts.cn/b/4-e/2+h;
return;
end
if small_x<(x+1)/2 && small_y<(y+1)/2
value = https://www.08ts.cn/a/4+b/4+c/4-d/2-e/2+h;
return;
end
end
至此,拟合实验完毕,具体思想就是“分而治之”,在小图中划分出所有3*3小方格(实际上像素值构成矩阵),根据最小误差拟合出每两个像素点中间点的值,依次填入大图 。
最后附上拟合成功图像

怎么用matlab画多项式拟合函数图像-数字图像处理matlab实验图像增强-_1

文章插图
Tags:


推荐阅读