




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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是相機(jī)內(nèi)部的原始圖片, 一般后綴名為.raw. 很多軟件都可以查看, 比如PS.我們相機(jī)拍照下來(lái)存儲(chǔ)在存儲(chǔ)卡上的.jpeg或其
17、它格式的圖片, 都是從.raw格式轉(zhuǎn)化過(guò)來(lái)的. .raw格式內(nèi)部的存儲(chǔ)方式有多種, 但不管如何, 都是前兩行的排列不同. 其格式可能如下: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)色值的兩倍, 因?yàn)槿搜蹖?duì)綠色更敏感, 所以綠色的分量更重.下面說(shuō)一下從bayer轉(zhuǎn)換成rgb圖的算法, RGB圖, 即為三色圖, 一個(gè)像素點(diǎn)就由RGB三
18、種顏色構(gòu)成的混合色, 而bayer圖一個(gè)像素就只有一個(gè)顏色, 或R或G或B. 因?yàn)閎ayer一個(gè)像素點(diǎn)只有一種顏色, 需要借助這個(gè)像素點(diǎn)周圍的顏色對(duì)它進(jìn)行插值(填充)另外的兩種顏色, 它本身的顏色就不用插了. 一般的算法是:對(duì)于插入R和B, Rx = ( R1 + R2 ) / 2; 或-取上邊和下邊的平均值, 或是左邊和右邊的平均值Rx = ( R1 + R2 + R3 + R4 ) / 4;-取四個(gè)邊的平均值B同理. 如:G B GR G RG B G對(duì)于中間的G, 它缺少 R和B, 用上下和左右的平均值進(jìn)行求值.對(duì)于B G BG R GB G B這個(gè)圖呢, 中間點(diǎn)R, 缺少G和B, G暫時(shí)沒(méi)討論, 那么 B, 就是從R的四個(gè)B角進(jìn)行求平均值.=如果插入G, 稍有些復(fù)雜.不過(guò)一般的算法與R和B一樣, 復(fù)雜的算法, 其復(fù)雜程度也提升一倍, 不過(guò)精度更高, 如果對(duì)于視頻監(jiān)測(cè)系統(tǒng)來(lái)說(shuō), 精度相對(duì)來(lái)說(shuō)不必要求太高, 用R或B的解法即可. 下面說(shuō)復(fù)雜的:對(duì)于圖:R1G1R4 G4 R G2 R2G3R3對(duì)于中間點(diǎn)R, 它需要插
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 品牌活動(dòng)日活動(dòng)策劃方案
- 啤酒公社活動(dòng)方案
- 圓夢(mèng)婚紗活動(dòng)方案
- 哈密本地團(tuán)建活動(dòng)方案
- 團(tuán)委營(yíng)銷活動(dòng)策劃方案
- 商場(chǎng)夏日活動(dòng)策劃方案
- 員工節(jié)儉活動(dòng)方案
- 國(guó)慶活動(dòng)米線活動(dòng)方案
- 國(guó)慶活動(dòng)商戶活動(dòng)方案
- 團(tuán)體建設(shè)室內(nèi)活動(dòng)方案
- 合并財(cái)務(wù)報(bào)表格式(2019版)
- 心臟射頻消融術(shù)
- 《商務(wù)郵件禮儀》課件
- 《配電自動(dòng)化系統(tǒng)》課件
- 創(chuàng)業(yè)基礎(chǔ)理論與實(shí)務(wù)(寧波財(cái)經(jīng)學(xué)院)知到智慧樹章節(jié)答案
- 《某飛機(jī)場(chǎng)物業(yè)管理服務(wù)方案》
- 《讓子彈飛》電影賞析
- 移動(dòng)OA系統(tǒng)建設(shè)方案
- DB34T∕ 2423-2015 安徽省城市道路交叉口信號(hào)控制設(shè)計(jì)規(guī)范
- 2023年南京市衛(wèi)健委所屬部分事業(yè)單位招聘考試試題及答案
- 安徽省合肥市2023-2024學(xué)年七年級(jí)下學(xué)期期末考試數(shù)學(xué)試卷(含答案)
評(píng)論
0/150
提交評(píng)論