赞
踩
在ISP图像处理中经常需要面对MIPI RAW数据和RAW数据,这里简单说明一下二者的差别。
传感器采集的RAW数据通常为10bit,存储RAW数据需要两个Byte,而其中有6个bit位是空着的,这样就有存储空间浪费。MIPI RAW数据充分利用了这个特性,采用5个Byte,共40bit存储4个RAW数据。这里以大端存储方式,给出这样存储的示意图。如下图所示:
从MIPI RAW数据恢复RAW数据的方法:
//b1,b2,b3,b4,b5分别为连续读出的五个uint8类型的数据,p1,p2,p3,p4为四个像素点的像素值,那么
p1 = (b1 << 2) + ((b5 ) & 0x3);
P2 = (b2 << 2) + ((b5 >> 2) & 0x3);
P3 = (b3 << 2) + ((b5 >> 4) & 0x3);
P4 = (b4 << 2) + ((b5 >> 6) & 0x3);
这里给出raw mipi10的读写matlab 代码示例,方便读者理解和认识mipi raw图像数据与unpacked raw数据
function rawImg = imreadRaw(fileName, width, height, isMipi) % read raw 10/12/14/16 or raw mipi 10 from a binary file fid = fopen(fileName, 'r'); if isMipi == 1 imgSize = width * height * 5 / 4; imgData = fread(fid, imgSize, 'uint8'); rawImg = zeros(width*height, 1); % byte0 | byte1 | byte2 | byte3 | byte4 % byte 0/1/2/3 store high 8 bits of pixel value, and byte4 store2 % low 2 bits of each pixel value % byte 0 rawImg(1:4:end) = imgData(1:5:end); % byte 1 rawImg(2:4:end) = imgData(2:5:end); % byte 2 rawImg(3:4:end) = imgData(3:5:end); % byte 3 rawImg(4:4:end) = imgData(4:5:end); % byte 4 rawImgLow2Bits = imgData(5:5:end); rawImg = rawImg * 4; rawImg(1:4:end) = rawImg(1:4:end) + bitand(bitshift(rawImgLow2Bits, 0), 3); rawImg(2:4:end) = rawImg(2:4:end) + bitand(bitshift(rawImgLow2Bits, -2), 3); rawImg(3:4:end) = rawImg(3:4:end) + bitand(bitshift(rawImgLow2Bits, -4), 3); rawImg(4:4:end) = rawImg(4:4:end) + bitand(bitshift(rawImgLow2Bits, -6), 3); else rawImg = fread(fid, width * height, 'uint16'); end fclose(fid); rawImg = reshape(rawImg, width, height)'; figure, imshow(uint16(rawImg), [0, 1023]) end
function imwriteRaw(fileName, rawImg, isMipi) [height, width] = size(rawImg); rawImg = rawImg'; rawImg = rawImg(:); fid = fopen(fileName, 'w'); rawImg = uint16(rawImg); if isMipi == 1 rawData = zeros(height * width * 5 / 4); % pix0 pix0 = rawImg(1:4:end); pix0Low2Bits = bitand(pix0, 3); % pix1 pix1 = rawImg(2:4:end); pix1Low2Bits = bitand(pix1, 3); % pix2 pix2 = rawImg(3:4:end); pix2Low2Bits = bitand(pix2, 3); % pix3 pix3 = rawImg(4:4:end); pix3Low2Bits = bitand(pix3, 3); byte0 = uint8(pix0 / 4); byte1 = uint8(pix1 / 4); byte2 = uint8(pix2 / 4); byte3 = uint8(pix3 / 4); % big endian mipi store byte4 = bitshift(pix3Low2Bits, 6) + bitshift(pix2Low2Bits, 4) + ... bitshift(pix1Low2Bits, 2) + pix0Low2Bits; rawData(1:5:end) = byte0; rawData(2:5:end) = byte1; rawData(3:5:end) = byte2; rawData(4:5:end) = byte3; rawData(5:5:end) = byte4; fwrite(fid, uint8(rawData), 'uint8'); else fwrite(fid, uint16(rawImg), 'uint16'); end fclose(fid); end
如下链接打包了读写raw数据及mipi raw数据的代码及仿真数据,方便读者下载复现和学习raw图像数据的存储格式和读写过程,如果出现问题,可以给笔者发私信沟通
https://download.csdn.net/download/luzhanbo207/33239267
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。