2014年6月18日 星期三

hw1:Image Scaling and Rotation

圖像縮放與旋轉程式撰寫
撰寫一個程式,讀取一張圖像(.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 










2014年6月13日 星期五

Assignment 6 Visible watermarking

作業內容:
主題: 可見浮水印 

請撰寫一個程式,讀取一張 256 色 RGB 全彩人物全彩圖像(.bmp 或.jpg 圖像格式都可)。 
(a) 設計一個程式在圖像中加入一個可見浮水印。(輸入的浮水印為一張單色圖像)。 


實作是蓋上去的圖比原圖還小:

利用 opencv的函式 addWeighted addWeighted(imageROI,1.0,logo,1.0,0.,imageROI);  
Parameters:
  • src1 – first input array.
  • alpha – weight of the first array elements.
  • src2 – second input array of the same size and channel number as src1.
  • beta – weight of the second array elements.
  • dst – output array that has the same size and number of channels as the input arrays.
  • gamma – scalar added to each sum.
  • dtype – optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().

實作是蓋上去的圖比原圖還小

原圖:                                                                                            欲加上的圖:




輸出結果:


2014年6月6日 星期五

Assgnment 5-Color transformation and processing

作業內容:
主題: 顏色空間轉換

請撰寫一個程式,讀取一張 256 色 RGB 全彩人物全彩圖像(.bmp 或.jpg 圖像格式都可)。
(a) 將輸入圖轉換至 HIS 顏色空間,並以灰階將 H,S,I 各顏色通道繪出。
(b) 撰寫一個函數偵測圖像的膚色區域(將膚色與背景區域區分出以單色圖像輸出。)


(a)
RGB-->HSI 核心轉換公式 :



轉換之後的核心程式碼:

R = rgbData[y, x, 0];
G = rgbData[y, x, 1];
B = rgbData[y, x, 2];

r = (double)R / (R + G + B);
g = (double)G / (R + G + B);
b = (double)B / (R + G + B);

value1 = 0.5 * ((r - g) + (r - b));
value2 = Math.Pow((Math.Pow(r - g, 2) + (r - b) * (g - b)), 0.5);

radial = Math.Acos(value1 / value2);
theta = (int)(radial * 180.0 / Math.PI);

if (!double.IsNaN(theta))
    h = (b > g) ? (360 - theta) : theta;
else
    h = 0;

s = 1 - 3 * CompareRGB.Min(r, g, b);
if (double.IsNaN(s))
    s = 0;

i = (R + G + B) / 3.0;

成果顯現:

h s i
(b) 撰寫一個函數偵測圖像的膚色區域(將膚色與背景區域區分出以單色圖像輸出。) 偵測每個的RGB值,接近膚色的為白色,其他則為黑色 成果顯現: