




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、Bayer轉(zhuǎn)換算法轉(zhuǎn)/* raw.h */#ifndef _RAW_H_ #define _RAW_H_ #define GP_OK 1 typedef enum BAYER_TILE_RGGB = 0, BAYER_TILE_GRBG = 1, BAYER_TILE_BGGR = 2, BAYER_TILE_GBRG = 3, BAYER_TILE_RGGB_INTERLACED = 4, BAYER_TILE_GRBG_INTERLACED = 5, BAYER_TILE_BGGR_INTERLACED = 6, BAYER_TILE_GBRG_INTERLACED = 7, BayerT
2、ile; int gp_bayer_expand (unsigned char *input, int w, int h, unsigned char *output, BayerTile tile); int gp_bayer_decode (unsigned char *input, int w, int h, unsigned char *output, BayerTile tile); int gp_bayer_interpolate (unsigned char *image, int w, int h, BayerTile tile); #endif /* raw.c */#inc
3、lude raw.h static const int tile_colours84 = 0, 1, 1, 2, 1, 0, 2, 1, 2, 1, 1, 0, 1, 2, 0, 1, 0, 1, 1, 2, 1, 0, 2, 1, 2, 1, 1, 0, 1, 2, 0, 1; #define RED 0 #define GREEN 1 #define BLUE 2 static int gp_bayer_accrue (unsigned char *image, int w, int h, int x0, int y0, int x1, int y1, int x2, int y2, in
4、t x3, int y3, int colour); int gp_bayer_expand (unsigned char *input, int w, int h, unsigned char *output, BayerTile tile) int x, y, i; int colour, bayer; unsigned char *ptr = input; switch (tile) case BAYER_TILE_RGGB: case BAYER_TILE_GRBG: case BAYER_TILE_BGGR: case BAYER_TILE_GBRG: for (y = 0; y h
5、; +y) for (x = 0; x w; +x, +ptr) bayer = (x&1?0:1) + (y&1?0:2); colour = tile_colourstilebayer; i = (y * w + x) * 3; outputi+RED = 0; outputi+GREEN = 0; outputi+BLUE = 0; outputi+colour = *ptr; break; case BAYER_TILE_RGGB_INTERLACED: case BAYER_TILE_GRBG_INTERLACED: case BAYER_TILE_BGGR_INTERLACED:
6、case BAYER_TILE_GBRG_INTERLACED: for (y = 0; y h; +y, ptr+=w) for (x = 0; x 1:ptr(w1)+(x1); break; return (GP_OK); #define AD(x, y, w) (y)*(w)*3+3*(x) int gp_bayer_interpolate (unsigned char *image, int w, int h, BayerTile tile) int x, y, bayer; int p0, p1, p2, p3; int value, div ; switch (tile) def
7、ault: case BAYER_TILE_RGGB: case BAYER_TILE_RGGB_INTERLACED: p0 = 0; p1 = 1; p2 = 2; p3 = 3; break; case BAYER_TILE_GRBG: case BAYER_TILE_GRBG_INTERLACED: p0 = 1; p1 = 0; p2 = 3; p3 = 2; break; case BAYER_TILE_BGGR: case BAYER_TILE_BGGR_INTERLACED: p0 = 3; p1 = 2; p2 = 1; p3 = 0; break; case BAYER_T
8、ILE_GBRG: case BAYER_TILE_GBRG_INTERLACED: p0 = 2; p1 = 3; p2 = 0; p3 = 1; break; for (y = 0; y h; y+) for (x = 0; x w; x+) bayer = (x&1?0:1) + (y&1?0:2); if ( bayer = p0 ) /* red. green lrtb, blue diagonals */ imageAD(x,y,w)+GREEN = gp_bayer_accrue(image, w, h, x-1, y, x+1, y, x, y-1, x, y+1, GREEN
9、) ; imageAD(x,y,w)+BLUE = gp_bayer_accrue(image, w, h, x+1, y+1, x-1, y-1, x-1, y+1, x+1, y-1, BLUE) ; else if (bayer = p1) /* green. red lr, blue tb */ div = value = 0; if (x (w - 1) value += imageAD(x+1,y,w)+RED; div+; if (x) value += imageAD(x-1,y,w)+RED; div+; imageAD(x,y,w)+RED = value / div; d
10、iv = value = 0; if (y (h - 1) value += imageAD(x,y+1,w)+BLUE; div+; if (y) value += imageAD(x,y-1,w)+BLUE; div+; imageAD(x,y,w)+BLUE = value / div; else if ( bayer = p2 ) /* green. blue lr, red tb */ div = value = 0; if (x (w - 1) value += imageAD(x+1,y,w)+BLUE; div+; if (x) value += imageAD(x-1,y,w
11、)+BLUE; div+; imageAD(x,y,w)+BLUE = value / div; div = value = 0; if (y (h - 1) value += imageAD(x,y+1,w)+RED; div+; if (y) value += imageAD(x,y-1,w)+RED; div+; imageAD(x,y,w)+RED = value / div; else /* blue. green lrtb, red diagonals */ imageAD(x,y,w)+GREEN = gp_bayer_accrue (image, w, h, x-1, y, x
12、+1, y, x, y-1, x, y+1, GREEN) ; imageAD(x,y,w)+RED = gp_bayer_accrue (image, w, h, x+1, y+1, x-1, y-1, x-1, y+1, x+1, y-1, RED) ; return (GP_OK); static int gp_bayer_accrue (unsigned char *image, int w, int h, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, int colour) int x 4 ; int
13、y 4 ; int value 4 ; int above 4 ; int counter ; int sum_of_values; int average ; int i ; x0 = x0 ; x1 = x1 ; x2 = x2 ; x3 = x3 ; y0 = y0 ; y1 = y1 ; y2 = y2 ; y3 = y3 ; counter = sum_of_values = 0 ; if(colour = GREEN) for (i = 0 ; i = 0) & (xi = 0) & (yi 2*vdiff) return (value 3 + value 2)/2 ; if(vd
14、iff 2*hdiff) return (value 1 + value 0)/2 ; /* for blue and red */ counter = sum_of_values = 0 ; for (i = 0 ; i = 0) & (xi = 0) & (yi h) value i = imageAD(xi,yi,w) + colour ; sum_of_values += value i ; counter+ ; average = sum_of_values / counter ; if (counter 4) return average ; /* Less than four s
15、urrounding - just take average */ counter = 0 ; for (i = 0 ; i average ; if (abovei) counter+ ; /* Note: counter = 0 indicates all values the same */ if (counter = 2) | (counter = 0) return average ; sum_of_values = 0 ; for (i = 0 ; i 4 ; i+) if (counter = 3) = abovei) sum_of_values += valuei ; retu
16、rn sum_of_values / 3 ; int gp_bayer_decode (unsigned char *input, int w, int h, unsigned char *output, BayerTile tile) gp_bayer_expand (input, w, h, output, tile); gp_bayer_interpolate (output, w, h, tile); return (GP_OK); Bayer圖像處理Bayer是相機內(nèi)部的原始圖片, 一般后綴名為.raw. 很多軟件都可以查看, 比如PS.我們相機拍照下來存儲在存儲卡上的.jpeg或其
17、它格式的圖片, 都是從.raw格式轉(zhuǎn)化過來的. .raw格式內(nèi)部的存儲方式有多種, 但不管如何, 都是前兩行的排列不同. 其格式可能如下:G R G R G R G RB G B G B G B GG R G R G R G RB G B G B G B G橫為2的倍數(shù), 豎為4的倍數(shù), 它們構(gòu)成了分辨率. 如, 上面則代表了 8 * 4 分辨率的Bayer圖.我們要知道的是, G = 2 * R 及 G = 2 * B, 即綠色值為紅色值或藍(lán)色值的兩倍, 因為人眼對綠色更敏感, 所以綠色的分量更重.下面說一下從bayer轉(zhuǎn)換成rgb圖的算法, RGB圖, 即為三色圖, 一個像素點就由RGB三
18、種顏色構(gòu)成的混合色, 而bayer圖一個像素就只有一個顏色, 或R或G或B. 因為bayer一個像素點只有一種顏色, 需要借助這個像素點周圍的顏色對它進(jìn)行插值(填充)另外的兩種顏色, 它本身的顏色就不用插了. 一般的算法是:對于插入R和B, Rx = ( R1 + R2 ) / 2; 或-取上邊和下邊的平均值, 或是左邊和右邊的平均值Rx = ( R1 + R2 + R3 + R4 ) / 4;-取四個邊的平均值B同理. 如:G B GR G RG B G對于中間的G, 它缺少 R和B, 用上下和左右的平均值進(jìn)行求值.對于B G BG R GB G B這個圖呢, 中間點R, 缺少G和B, G暫時沒討論, 那么 B, 就是從R的四個B角進(jìn)行求平均值.=如果插入G, 稍有些復(fù)雜.不過一般的算法與R和B一樣, 復(fù)雜的算法, 其復(fù)雜程度也提升一倍, 不過精度更高, 如果對于視頻監(jiān)測系統(tǒng)來說, 精度相對來說不必要求太高, 用R或B的解法即可. 下面說復(fù)雜的:對于圖:R1G1R4 G4 R G2 R2G3R3對于中間點R, 它需要插
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年電子商務(wù)法與市場監(jiān)管基礎(chǔ)知識測試試題及答案
- 2025年高等數(shù)學(xué)基礎(chǔ)知識應(yīng)用能力考試試題及答案
- 2025年城市環(huán)境保護(hù)與可持續(xù)發(fā)展考核題及答案
- 檔案密集架采購招標(biāo)文件
- 采購合同履行過程中的質(zhì)量監(jiān)控
- 叉車租賃押金擔(dān)保及維修服務(wù)合同
- 綜合性茶園資源利用與保護(hù)承包合同
- 豐收玉米活動方案
- 中考復(fù)習(xí)指導(dǎo)活動方案
- 醫(yī)用氣體使用管理制度
- 公務(wù)員制度講座-終結(jié)性考核-國開(SC)-參考資料
- 2025屆北京市人大學(xué)附屬中學(xué)高三下學(xué)期一模考試英語試題含解析
- 行政案例分析-終結(jié)性考核-國開(SC)-參考資料
- 操作系統(tǒng)-001-國開機考復(fù)習(xí)資料
- 教育機構(gòu)教師培訓(xùn)與考核制度
- 糖尿病口服降糖藥物分類
- 高標(biāo)準(zhǔn)農(nóng)田泵房使用協(xié)議書(2篇)
- 第45屆世界技能大賽烹飪(西餐)項目全國選拔賽技術(shù)工作文件
- 科幻小說閱讀(原卷版)-2023年浙江中考語文復(fù)習(xí)專練
- 化妝品代加工保密協(xié)議
- 2024年高等教育法學(xué)類自考-00229證據(jù)法學(xué)考試近5年真題附答案
評論
0/150
提交評論