如何读取10位原始图像?其中包含RGB-IR数据

问题描述:

我想知道如何从我的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

我用下面的图像处理舞台:

  • 拜耳马赛克颜色信道分离。
  • 线性拉伸每个颜色通道。
  • 简单的白平衡。
  • 用绿色替换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