您的位置:首页 > 其它

灰度插值实验

2016-05-05 15:26 155 查看

灰度插值实验

才疏学浅,资历欠佳,难免有误,望有心人批评指正。

本文旨在展示绘图插值

最近邻插值

Clear[T, img, mat, row, col, mat2, x, y, x2, y2, v, v2, img2];
\[Theta] = 30 Degree;
sin = Sin[\[Theta]] // N; cos = Cos[\[Theta]] // N;
T = {{cos, -sin, 0}, {sin, cos, 0}, {0, 0, 1}};
(*T={{2,0,0},{0,1,0},{0,0,1}};*)
iT = Inverse[T];
img = Import["lena_gray_256.tif", "TIFF"];
mat = ImageData[img, "Byte"];
{row, col} = Dimensions[mat];
mat2 = Table[0, {row}, {col}];
For[y = 1, y <= row, y++, For[x = 1, x <= col, x++, v = {x, y, 1};
v2 = iT.v;(*点积*){x2, y2, t} = Round[v2];(*最近邻*)
If[1 <= x2 <= col && 1 <= y2 <= row, mat2[[y, x]] = mat[[y2, x2]]
]
];
];
img2 = Image[mat2, "Byte"];
GraphicsRow[{img, img2}, ImageSize -> Medium]




双线性插值

affine[img_, T_] :=
Module[{iT, mat, row, col, mat2, x, y, v2, p, x2, y2, p0, x0, y0, u,
v, f, f1, f2, img2}, iT = Inverse[T];
mat = ImageData

[img]http://img.blog.csdn.net/20160505152517818" border="0" >
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: