圖像縮放與旋轉程式撰寫
撰寫一個程式,讀取一張圖像(.bmp 或.jpg 圖像格式)
(1)使用下列內插演算法實作影像大小縮放調整程式。
(a) Nearest Neighbor Interpolation
(b) Bilinear Interpolation
(c) Bicubic Interpolation (加分題)
(2)撰寫圖像旋轉程式。
(a) Nearest Neighbor Interpolation
 |
一般影像幾何轉換都會用 Target - to - Source Mapping 也是就是將縮放後的影像 g(u, v) 計算它在原始影像 f 對映 的灰度值 但座標 (u, v) 對映至原來的座標 (x, y) x 跟 y 可能不是整數 因此不能直接用 f(x,y) 代替 g(u, v) 所以必須用原始影像 f 在整數點的灰度值來推估非整數點的灰度值推估非整數座標(x, y)灰度值的方法叫插補(interpolation) 最簡單的插補法就是 NNI (nearest neighbor interpolation) 也就是找離 (x, y) 最近的整數點 (xout, yout) 以 f(xout, yout) 代替未知的 f(x, y) 而 f(x, y) 就是縮放後 g(u, v) 的值
xout = int (x+0.5) yout = int(y+0.5)
其中int 就是取整數,也就是 floor 運算。
(b) Bilinear Interpolation |
沒有留言:
張貼留言