2016-09-21 74 views
1

我想知道如何從我的10位原始(它具有rgb-ir imagedata)數據中提取rgb圖像?如何讀取10位原始圖像?其中包含RGB-IR數據

如何在Python或MATLAB中讀取?

在拍攝時的相機分辨率爲1280×720: 室內照片Image for download 外拍Image 2 for download

相機型號:E-CAM40_CUMI4682_MOD

非常感謝

+0

什麼是10位圖像的格式或佈局? –

+2

如果您想知道如何使用Python或Matlab讀取圖像,爲什麼將它標記爲C++?你知道C++與Python不同嗎? –

+0

ouh謝謝你,我在這裏初學者 – xavysp

回答

7

我用下面的圖像處理舞臺:

  • 拜耳馬賽克顏色信道分離。
  • 線性拉伸每個顏色通道。
  • 簡單的白平衡。
  • 用綠色替換IR顏色通道(將圖像轉換爲標準拜耳格式)。
  • 恢復拜耳馬賽克。
  • 簡單的伽馬校正。
  • 去馬賽克

代替處理IR顏色通道,我與綠色信道代替它。

根據您添加的RGB圖像,我找到了CFA的順序。
的CFA(濾色器陣列)的順序是:

B | G 
-- -- 
IR| R 

以下Matlab代碼處理的圖像爲RGB:

srcN = 1280; 
srcM = 720; 

f = fopen('image_raw.raw', 'r'); 

%Read as transposed matrix dimensions, and transpose the matrix. 
%The reason for that, is that Matlab memory oreder is column major, and 
%raw image is stored in row major (like C arrays). 
I = fread(f, [srcN, srcM], 'uint16'); 
fclose(f); 
I = I'; 

%Convert from range [0, 1023] range [0, 1] (working in double image format). 
I = I/(2^10-1); 

%Bayer mosaic color channel separation 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Assume input format is GBRG Bayer mosaic format. 
%Separate to color components. 
B = I(1:2:end, 1:2:end); 
G = I(1:2:end, 2:2:end); 
IR = I(2:2:end, 1:2:end); 
R = I(2:2:end, 2:2:end); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


%Linear stretching each color channel. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Linear streatch blue color channel. 
B = imadjust(B, stretchlim(B, [0.02 0.98]),[]); 

%Linear streatch green channel. 
G = imadjust(G, stretchlim(G, [0.02 0.98]),[]); 

%Linear streatch red color channel. 
R = imadjust(R, stretchlim(R, [0.02 0.98]),[]); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Simple white balance 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Median or R, G and B. 
rgb_med = [median(R(:)), median(G(:)), median(B(:))]; 
rgb_scale = max(rgb_med)./rgb_med; 

%Scale each color channel, to have the same median. 
R = R*rgb_scale(1); 
G = G*rgb_scale(2); 
B = B*rgb_scale(3); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


%Restore Bayer mosaic. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Insert streached color channnels back into I. 
I(1:2:end, 1:2:end) = B; 
I(1:2:end, 2:2:end) = G; 
%I(2:2:end, 1:2:end) = G; %Replace IR with Green. 
I(2:2:end, 2:2:end) = R; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Replace IR with green - resize green to full size of image first. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
T = imresize(G, [srcM, srcN]); %T - temporary green, size 1280x720 
I(2:2:end, 1:2:end) = T(2:2:end, 1:2:end); %Replace IR with Green. 
I = max(min(I, 1), 0); %Limit I to range [0, 1]. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Simple gamma correction 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
gamma = 0.45; 
I = I.^gamma; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Demosaic 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Convert to uint8 (range [0, 255]). 
I = uint8(round(I*255)); 
RGB = demosaic(I, 'bggr'); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

imshow(RGB); 

結果:

enter image description here

現在的顏色正常...


戶外圖像處理:

應用「室內」處理戶外圖像上,得到如下結果:

enter image description here

白樹是近紅外光譜滲透的跡象R,G和B像素(不僅限於紅外像素)。
植被的葉綠素在近紅外光譜中有高反射。請參閱:http://missionscience.nasa.gov/ems/08_nearinfraredwaves.html‌​,然後在Google上進行搜索。
需要從紅色,綠色和藍色通道中減去紅外。


我用下面的圖像處理階段:

  • 拜耳鑲嵌彩色信道分離。
  • 從紅色,綠色和藍色通道減去IR「剩餘」。
  • 線性拉伸每個顏色通道。
  • 簡單的白平衡。
  • 恢復拜耳馬賽克。
  • 簡單的伽馬校正。
  • 去馬賽克。
  • 將RGB圖像調整爲較低的分辨率。

以下Matlab代碼處理室外圖像RGB:

srcN = 1280; 
srcM = 720; 

f = fopen('ir_6.raw', 'r'); 

%Read as transposed matrix dimensions, and transpose the matrix. 
%The reason for that, is that Matlab memory oreder is column major, and 
%raw image is stored in row major (like C arrays). 
I = fread(f, [srcN, srcM], 'uint16'); 
fclose(f); 
I = I'; 

%Convert from range [0, 1023] range [0, 1] (working in double image format). 
I = I/(2^10-1); 

%Bayer mosaic color channel separation 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Assume input format is GBRG Bayer mosaic format. 
%Separate to color components. 
B = I(1:2:end, 1:2:end); 
G = I(1:2:end, 2:2:end); 
IR = I(2:2:end, 1:2:end); 
R = I(2:2:end, 2:2:end); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


%Subtract IR "surplus" from R, G and B. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%The coefficients were tuned by trial and error... 
ir_r = 1.3; % 130% of IR radiation is absorbed by red pixels??? 
ir_g = 0.35; % 35% of IR radiation is absorbed by green pixels. 
ir_b = 0.3; % 30% of IR radiation is absorbed by blue pixels. 

IR = imresize(IR, size(I)); %Resize IR to the size of I. 
IR = max(min(IR, 1), 0); %Limit IR to range [0, 1] (because imresize values slightly outside the range of input). 

R = R - IR(2:2:end, 2:2:end)*ir_r; %Subtract IR for R (IR scale coefficient is ir_r). 
G = G - IR(1:2:end, 2:2:end)*ir_g; %Subtract IR for G (IR scale coefficient is ir_g). 
B = B - IR(1:2:end, 1:2:end)*ir_b; %Subtract IR for B (IR scale coefficient is ir_b). 

R = max(min(R, 1), 0); %Limit IR to range [0, 1] 
G = max(min(G, 1), 0); 
B = max(min(B, 1), 0); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


%Linear stretching each color channel. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Linear streatch blue color channel. 
B = imadjust(B, stretchlim(B, [0.02 0.98]),[]); 

%Linear streatch green channel. 
G = imadjust(G, stretchlim(G, [0.02 0.98]),[]); 

%Linear streatch red color channel. 
R = imadjust(R, stretchlim(R, [0.02 0.98]),[]); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Simple white balance 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Median or R, G and B. 
rgb_med = [median(R(:)), median(G(:)), median(B(:))]; 
rgb_scale = max(rgb_med)./rgb_med; 

%Scale each color channel, to have the same median. 
R = R*rgb_scale(1); 
G = G*rgb_scale(2); 
B = B*rgb_scale(3); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 


%Restore Bayer mosaic. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Insert streached color channnels back into I. 
I(1:2:end, 1:2:end) = B; 
I(1:2:end, 2:2:end) = G; 
I(2:2:end, 2:2:end) = R; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Replace IR with green - resize green to full size of image first. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
T = imresize(G, [srcM, srcN]); %T - temporary green, size 1280x720 
I(2:2:end, 1:2:end) = T(2:2:end, 1:2:end); %Replace IR with Green. 
I = max(min(I, 1), 0); %Limit I to range [0, 1]. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Simple gamma correction 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
gamma = 0.45; 
I = I.^gamma; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%Demosaic 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%Convert to uint8 (range [0, 255]). 
I = uint8(round(I*255)); 
RGB = demosaic(I, 'bggr'); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

RGB = imresize(RGB, size(I)/2); %Shrink size of RGB image for reducing demosaic artifacts. 

imshow(RGB); 

結果是不那麼好,但它表明,IR信道可以從紅,綠和藍色通道中減去的概念。
還有很多工作要做...
結果圖像:

enter image description here

原因「假色」綠色補丁:
飽和像素,紅色通道(在原始飽和輸入),處理不當。
問題可以通過減少曝光(以較低的曝光時間拍攝)來解決。

+0

您是如何解決這個問題的? –

+0

其實我錯過了紅外線的顏色通道。還有工作要做... – Rotem

+0

所以謝謝你,我會檢查並改進ir和rgb圖像。 rgb中的圖像就像這樣[點擊這裏查看](https://drive.google.com/file/d/0B0givAGTBMIwc2ctYlI0SXhZWDg/view?usp=sharing) – xavysp

相關問題