主要成像格式:RAW\RGB\YUV
RAW ⽂件存储格式
Plain RAW
移位转变bit
MIPI RAW packet
• MIPI CSI2 主要是针对传输设置的格式。所以在它的packet size的设定是整好 4个像素放到5个bytes(50bits)中。并且在由10bit 转 8bit RAW操作的时候不需要移位操作。直接抛弃第5个bytes 中的内容就可以了。另外MIPI10bit RAW格式的每⾏以8个像素 做对⻬,不⾜位补0。
MIPI packet在frame中的排列方式
在MIPI的帧中只需要包的长度对齐就好。另外MIPI10bit RAW格式的每行以8 pixels做对齐
不过实际从得到MIPI文件在帧长度后面有很多无用数据
MIPI RAW 读取流程
计算对齐之后图像长宽——从文件中读取数据——整理成对齐后矩阵——分别提取子矩阵——将第五像素的子矩阵的低位加到其它矩阵——重新合并图像——去除掉多余的像素
本课程使用的Raw格式
SRGB
RGB:Matlab/python
BGR:OpenCV
YCbCr
YCbCr
NV12 to YCbCr 444
Repeat 函数
Numpy.repeat(a,repeats,axis=None)
输入的使array a:返回的是重复后的数组repeated_array,在给定的axis方向上进行操作,其他维度的shape和输入一样
repeats:可以是单个整数,也可以是整数数组,指明沿axis每个元素广播(重复)的次数
axis: 默认就是把原来的数组变成一维再重复,返回的也是一维的数组,可以指定需要做重复的维度
Cb=Cb.repeat(2,0)
Cb=Cb.repeat(2,1)
Cr=Cr.repeat(2,0)
Cr=Cr.repeat(2,1)
压缩非压缩
部分代码
raw_image_show.py
import cv2 as cv
import numpy as np
import os
from matplotlib import pyplot as plt
from scipy import misc
from skimage import io
from mpl_toolkits.mplot3d import Axes3D
'''
mono, the image data value is between 0~1
'''
def raw_image_show_fullsize(image, height, width):
x = width / 100
y = height / 100
plt.figure(num='test', figsize=(x, y))
plt.imshow(image, camp='gray', interpolation='bicubic', vmax=1.0)
plt.xticks([]), plt.yticks([]) # 隐藏 X轴 和 Y轴 的标记位置和labels
plt.show()
print('show')
def raw_image_show_3D(image, height, width):
fig = plt.figure()
# ax = Axes3D(fig)
ax = plt.subplot(1, 1, 1, projection='3d')
X = np.arange(0, width)
Y = np.arange(0, height)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X ** 2 + Y ** 2)
Z = image
# 具体函数方法可用 help(function)查看,如:help(ax.plot_surface)
# ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap='rainbow')
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
plt.show()
print('show')
def raw_image_show_thumbnail(image,height,width):
x = width / 800
y = height / 800
plt.figure(num='test',figsize=(x,y))
plt.imshow(image,camp='gray',interpolation='bicubic',vmax=1.0)
plt.xticks([]), plt.yticks([]) # 隐藏 X轴 和 Y轴的标记位置和labels
plt.show()
def raw_image_show_fackecolor(image,height,width,pattern):
x = width /100
y= width/100
rgb_img = np.zeros(shape=(height,width,3))
R = rgb_img[:,:,0]
GR = rgb_img[:,:,1]
GB = rgb_img[:,:,1]
B = rgb_img[:,:,2]
if pattern== "RGGB":
R[::2,::2] = image[::2,::2]
GR[::2,1::2]=image[::2,1::2]
GB[1::2,::2]=image[1::2,::2]
B[1::2,1::2]=image[1::2,1::2]
elif pattern== "GRBG":
GR[::2,::2]=image[::2,::2]
R[::2,1::2]=image[::2,1::2]
B[1::2,::2]=image[1::2,::2]
GB[1::2,1::2]=image[1::2,1::2]
elif pattern== "GBRG":
GB[::2,::2]=image[::2,::2]
B[::2,1::2]=image[::2,1::2]
R[1::2,::2]=image[1::2,::2]
GR[1::2,1::2]=image[1::2,1::2]
elif pattern== "BGGR":
B[::2,::2]=image[::2,::2]
GB[::2,1::2]=image[::2,1::2]
GR[1::2,::2]=image[1::2,::2]
R[1::2,1::2]=image[1::2,1::2]
else:
print("show failed")
return
plt.figure(num='test',figsize=(x,y))
plt.imshow(rgb_img,interpolation='bicubic',vmax=1.0)
plt.xticks([]),plt.yticks(([]))
plt.show()
print('show')
def test_case_fullsize():
b = np.fromfile("x.raw",dtype="uint16")
print("b shape", b.shape)
print('%#x' % b[0])
b.shape = [3072,4096]
out = b
out = out / 1024.0
raw_image_show_fullsize(out,3072,4096)
def test_case_thumbnail():
b = np.fromfile("x.raw",dtype="uint16")
print("b shape",b.shape)
print('%#x' % b[0])
b.shape = [3072,4096]
out = b
out = out / 1024.0
raw_image_show_thumbnail(out,3072,4096)
def test_case_fakecolor():
b = np.fromfile("x.raw",dtype="uint16")
print("b shape",b.shape)
print('%#x' % b[0])
b.shape = [3072,4096]
out = b
out = out / 1024.0
raw_image_show_fackecolor(out, 3072, 4096,"BGGR")
def test_case_3D():
b=np.fromfile("x.raw",dtype="uint16")
print("b shape",b.shape)
print("%#x" % b[0])
b.shape=[3072,4096]
c=b[0:100,0:120]
out = c
out = out / 1024.0
raw_image_show_3D(out,100,120)
if __name__ == "__main__":
print('This is main of module')
test_case_fakecolor()
3D—