👨‍💻SFR sfrmat3 Code Learning
2017-8-20
| 2024-11-8
0  |  阅读时长 0 分钟
type
status
date
slug
summary
tags
category
icon

Document

 

ISO Flowchart of e-SFR measurement algorithm

notion image
 

Diagram depicting the key steps of the e-SFR algorithm

notion image
notion image
 
 

Read in images

Lens shading correction

解决由于lens的光学特性,由于镜头对于光学折射不均匀导致的镜头周围出现阴影的情况。
Code
numpy.meshgrid()理解_lllxxq141592654的博客-CSDN博客
网格点是什么? 坐标矩阵又是什么鬼? 看个图就明白了: 图中,每个交叉点都是,描述这些 网格点的坐标的矩阵,就是 坐标矩阵。 再看个简单例子 A,B,C,D,E,F是6个网格点,坐标如图,如何用矩阵形式( 坐标矩阵)来批量描述这些点的坐标呢? 答案如下: 这就是 坐标矩阵 --横坐标矩阵中的每个元素,与纵坐标矩阵中对应位置元素,共同构成一个点的完整坐标。如B点坐标。 下面可以自己用matplotlib来试一试,输出就是上边的图 如果对matplotlib不熟悉,可能只知道用一列横坐标(线性代数中的1维列向量),一列纵坐标生成(两者元素个数相等)一些点。但是实际上,给matplotlib的坐标信息是矩阵也是可以的,只要横纵坐标的尺寸一样。都会按照对应关系生成点。 但是有需要注意的地方,按照矩阵给坐标点信息,matplotlib会把 横坐标矩阵中, 每一列对应的点当做同一条线。 举个例子,把上面的代码 plot的 linestyle=''删掉,或者变成 linestyle='-'(这个操作把图的线型改为默认状态),就会发现A-D是连接的,B-E是连接的,C-F是连接的,也即,会认为你输入的是3条线,如图 作为练习,自己试着生成如下结果 提示:线型等关键字参数设置可用如下代码 plt.plot(x, y, marker='.', # 点的形状为圆点 markersize=10, # 点设置大一点,看着清楚 linestyle='-.') # 线型为点划线 答案 import numpy as np import matplotlib.pyplot as plt x = np.array([[0, 1, 2, 3],
numpy.meshgrid()理解_lllxxq141592654的博客-CSDN博客
 

Split raw image into 4 sub-channels

Bayer

R, Gr (Green Row), B, Gb (Green Balance)
 
 

Undemosaiced

In this document, we sometimes refer to RAW files from commercial cameras or development systems as Camera RAW to distinguish them from Bayer RAW files, which are standard monochrome image files that contain undemosaiced (Bayer) data.
Camera RAW≠Bayer RAW
Undemosaiced~=4 channels
Code
 

Calculate fixed sizes for the chart

Code (Load config)
notion image
 

Threshold image and find regions

notion image
Code
Find the coordinate of centroids
 

Calculate the SFR

💡
for square; square_names=[c, r, t, l, ......]; (for each square)
💡
for patch; patch_name=[t, b, r, l]; (for each ROI)
💡
for chan; channels(for each colour channel)
notion image
Code (Get the scope of the ROI)
  1. The "Threshold image and find regions" have already found the ideal coordinate of each square.
  1. The real square coordinate has the minimum distance between the ideal one and itself.
Sketch map of finding the ROI (named as patch & sub_patch in MATLAB codes)
  • t
    • notion image
  • b
    • notion image
  • l
    • notion image
  • r
    • notion image
 

sfrmat3

dat = computed sfr data
oename optional name of oecf LUT file containing 3xn or 1xn array. The camera optoelectronic conversion function (OECF). 伽马校正部分用于校正非线性光输出(与之对应的是显示器的信号输入)。光输入强度和电信号输出强度之间的关系称为相机光电转换函数(OECF),为图像捕获设备提供伽马校正曲线形状。
 

Size or Shape of "a" (img_patch)

 

rotatev2

Code
If the difference between 2 rows > 2 columns: rotate to vertical
notion image
 

Edge contrast

tleft, tright, test
notion image
 
 
Loop for each color
notion image
 

The first estimate of edge slope & offset

Code
deriv1 (Compute derivative)? (27 May 2020 updated to use 'same' conv option)
Apply convolution for each row of the image matrix.
💡
The "derivative" it calculated is quite likely! Whereas, I don't handle how to calculate the derivative of a discrete sequence!
centroid (Compute centroid for derivative array for each line in ROI)
💡
Different from ISO document.
notion image
notion image
Each row (r) of the edge spread image is an estimate of the camera edge spread function (ESF). Each of these ESFs is differentiated to form its discrete line spread function (LSF). The position of the centroid (C) of each r LSF is determined along the continuous variable x, where x has the range (1, X) [see Formula (D.3)].
💡
It really works! If you don't believe it, use x=[3, 2, 3] to make a test.
💡
Though it is in operation, I have no idea about the weird algorithm.
 

The final estimate of edge slope and offset

Code
findedge 线性拟合(Done in the first estimate)
  • slope从高次幂开始
  • cent=slope(1)*index + slope(2)
  • place(n) =fitme(color,1)*n + fitme(color,2)
  • slope从高次幂开始
  • cent=slope[0]*index + slope[1]
  • place(n) =fitme[color,0]*n + fitme[color,1]
x = fitme(color, 1) y + fitme(color, 2) % so the slope is the inverse of the one that you may expect
hamming: place= mid = midpoint (maximum) of the window function
If mid = (n+1)/2 then the usual symmetric Hamming
centroid (Mentioned above)
💡
根据centroid线性拟合;根据线性拟合再计算centroid;根据线性的centroid再计算slope
 

Edge slope judgment

Code
notion image
 

Correction (Derivative correction)

Code (fir2fix)
fir2fix
notion image
D ( k) is the correction for the frequency response of the discrete derivative used to derive the point spread function from the edge spread function,
 

Project (shift the image data along the edge direction to the edge of the ROI)

Code
project 到线性拟合的方向上
Projects the data in array bb along the direction defined by Used by sfrmat11 and sfrmat2 functions. Data is accumulated in 'bins' that have a width pixel.
notion image
 

Compute the one-dimensional derivative of the edge-spread function

Code
 

Shift to center the line spread function (LSF) vector

Code
cent: shift of one-dimensional array, so that is located at .
是横坐标的中心,centroid 也返回横坐标,但与纵坐标数值有关
 

Apply a Hamming window to the LSF vector

Code
 

Compute the discrete Fourier transform (DFT) of the windowed, binned LSF vector; Compute the modulus of the complex DFT array

 

Normalize the modulus vector by the zero-frequency value (first element of the array) to obtain the E-SFR

 

Correct the E-SFR for the discrete derivative response

Code
 

Report E-SFR result

Code
 

Derived metrics

Construct the square_results matrix from patch_results

根据特殊算出的采样频率 freq 作为样本点(横坐标),对 mtf 值(对应值)进行插值,在查询
Screenshots of MATLAB & Python
notion image
notion image
  • patch_result: each color channel
 

Condense and assess patch results

💡
Each SFR data of a color channel is equal to the mean of t, b, r, l
 

Calculate tilt and falloff

tilt

Screenshots of Python & MATLAB
notion image
  1. for outer_name: outer 的 05Data h & v,列拼接
  1. for outer_name: 对行求 mean,形成 outer_data
  1. for outer_name: outer_data 取 Gr 和 Gb 行,行拼接
  1. 求列 mean
  1. ;
 

falloff

  1. fetch 05Data Gr & Gb from center
  1. calculate the mean
  1. falloff = center_data - mean(outer_data);
 

Write data

  • notes
  • Hawpu
  • What I Have Done in HawpuCalibLibtxt1 Code Learning
    Loading...