【问题标题】:How can I read 10-bit Raw image? which contain RGB-IR data如何读取 10 位原始图像?其中包含 RGB-IR 数据
【发布时间】:2017-01-30 02:01:53
【问题描述】:

我想知道如何从我的 10 位原始(它具有 rgb-ir 图像数据)数据中提取 rgb 图像?

如何在 Python 或 MATLAB 中阅读?

拍摄时的相机分辨率为 1280x720: 室内照片Image for download 户外写真Image 2 for download

相机型号:e-CAM40_CUMI4682_MOD

非常感谢

【问题讨论】:

  • 10 位图像的格式或布局是什么?
  • 如果您想知道如何使用 Python 或 Matlab 读取图像,为什么将其标记为 C++?您知道 C++ 是与 Python 不同的语言吗?
  • 谢谢你,我是初学者
  • 你为什么上传一个可执行文件作为相机描述 - 没有人会运行它。
  • 我似乎无法让您的数字发挥作用。如果您的图像为 1280x720,则您有 921,600 像素。您的文件是 1,843,200 字节,因此您似乎每个像素有 2 个字节,或每个像素有 16 位。这与您所说的每像素 10 位有何关系?那里有RGB和IR吗?如果是这样,RGB 是 6 位还是其他?

标签: python matlab numpy image-processing


【解决方案1】:

我使用了以下图像处理阶段:

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

结果:

现在颜色正常了……


户外图像处理:

对室外图像应用“室内”处理,得到如下结果:

白树是近红外光谱渗透到 R、G 和 B 像素(不仅是 IR 像素)的标志。
植被的叶绿素在近红外光谱中具有高反射率。请参阅:http://missionscience.nasa.gov/ems/08_nearinfraredwaves.html‌​,并在 Google 上搜索。
需要从红色、绿色和蓝色通道中减去 IR。


我使用了以下图像处理阶段:

  • 拜耳马赛克颜色通道分离。
  • 从红色、绿色和蓝色通道中减去 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 颜色通道。还有很多工作要做……
  • 所以谢谢你,我会检查和改进 ir 和 rgb 图像。 rgb中的图像是这样的click here to see
  • 感谢您的反馈,我的大错误,我在上面评论中添加的图像是用其他相机拍摄的,这是用同一相机拍摄的图像(See3CAM_CU40),Click to see image我想可能是 g|b::r|ir ?
  • 我找到了恢复颜色的方法。
  • 非常感谢,但是您阅读过任何文章吗?这样做,如果可以,你能和我分享一下吗?
猜你喜欢
  • 2018-03-17
  • 2016-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多