Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .assets/calib/1600_K1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/calib/IMG_0016.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/calib/IMG_0483.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/calib/log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 0 additions & 17 deletions docs/calib.md

This file was deleted.

65 changes: 65 additions & 0 deletions docs/calib_cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 噪声标定

## 先决条件

### 1. Rawpy

标定的代码使用了 rawpy 包,可根据此说明安装(https://pypi.org/project/rawpy/)

注意:如果无法在 Mac(m1/m2)上安装 rawpy,您可以参考这个issue(https://github.com/letmaik/rawpy/issues/171)

### 2. 数据

建议将待标定的数据按照不同的相机分别组织到各自的文件夹中。在每个相机文件夹内,应进一步根据不同的 ISO 值将数据分到几个子文件夹中。

## 数据拍摄与原理

我们分别使用了5种不同型号的相机分别拍摄了色卡(24个色块)和黑图。色卡如下图所示:

<p align="center">
<img src='../.assets/calib/IMG_0483.jpg' alt='ICCV23_LED_LOGO' width='600px'/>
</p>

dark图像如下图所示:

<p align="center">
<img src='../.assets/calib/IMG_0016.jpg' alt='ICCV23_LED_LOGO' width='600px'/>
</p>
其中色卡和黑图都选取了9个不同的ISO值,每个ISO值均拍摄了15张相同的图像。因此根据ELD[^1]中提到的公式:

$$\text{Var}(D) = K(K I)+\text{Var}\left(N_o\right)$$

相当于我们对每个ISO下的色卡图,都获取了24组不同的数据点,因此我们可以拟合出一条直线,并得到当前相机当前ISO下的K和信号无关噪声的方差,如下图:

<p align="center">
<img src='../.assets/calib/1600_K1.png' alt='ICCV23_LED_LOGO' width='600px'/>
</p>

接着,我们根据拍摄的dark图像获取其他参数,首先,我们可以通过对整张图像求均值和方差得到Read Noise(假设服从TL分布或者高斯分布)与row噪声的和的分布参数;随后,我们可以分别获得当Read Noise服从TL分布或高斯分布这两种假设的参数。

最后,根据ELD[^1]中的公式:

$$\log (\sigma_{TL}) \mid \log (K) \sim \mathcal{N}(a_{TL} \log (K)+b_{TL}, \hat{\sigma}_{TL})$$

$$\log (\sigma_r) \mid \log (K) \sim \mathcal{N}(a_r \log (K)+b_r, \hat{\sigma}_r)$$

我们可以对每个相机在不同ISO下得到的K和分布参数作为数据点,拟合出两者之间的对数线性关系,例如下图:

<p align="center">
<img src='../.assets/calib/log.png' alt='ICCV23_LED_LOGO' width='600px'/>
</p>

## 标定过程

对于标定过程,您可以通过直接按照主函数中给出的代码执行所有步骤一次完成,也可以根据您的需要分别执行每个步骤。这些步骤包括选择颜色块的位置、校准颜色块以获取 K 值、校准暗图像以获取其他参数,以及拟合 log(K) 和 log(方差)。

## 致谢

本代码参考了ELD和PMN的相关工作,在此向ELD[^1]和PMN[^2]的作者和贡献者致谢!

[^1]: 1https://arxiv.org/abs/2108.02158

[^2]: https://github.com/megvii-research/PMN/tree/TPAMI



65 changes: 65 additions & 0 deletions docs/calib_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Noise calibration

## Prerequisites

### 1. Rawpy

The calibration code the raspy package, which can be installed based on this instructions(https://pypi.org/project/rawpy/)

Note: If rawpy cannot be installed on Mac(m1/m2), you can refer to this issue(https://github.com/letmaik/rawpy/issues/171)

### 2. data

It is recommended that you organize the data to be calibrated into separate folders for each camera. Within each camera folder, you should further divide the data into several subfolders based on different ISO values.

## Data Capture and Principles

We used five different models of cameras to separately capture color cards (24 color blocks) and black images. The color card is shown in the following image:

<p align="center">
<img src='../.assets/calib/IMG_0483.jpg' alt='ICCV23_LED_LOGO' width='600px'/>
</p>

Dark images are as shown in the image below:

<p align="center">
<img src='../.assets/calib/IMG_0016.jpg' alt='ICCV23_LED_LOGO' width='600px'/>
</p>
Both the color card and the black images were captured at nine different ISO values, with 15 identical images taken at each ISO value

$$\text{Var}(D) = K(K I)+\text{Var}\left(N_o\right)$$

Therefore, according to the formula mentioned in ELD[^1], it is equivalent to obtaining 24 sets of different data points for each color card image under each ISO. Hence, we can fit a straight line and obtain the K and the signal-independent noise for the current camera at the current ISO:

<p align="center">
<img src='../.assets/calib/1600_K1.png' alt='ICCV23_LED_LOGO' width='600px'/>
</p>

Next, we obtain other parameters based on the captured dark images. Firstly, we can derive the distribution parameters of the sum of Read Noise (assuming it follows a TL distribution or a Gaussian distribution) and row noise by calculating the mean and variance of the entire image. Subsequently, we can obtain the parameters for the two assumptions where the Read Noise follows either a TL distribution or a Gaussian distribution.

Finally, according to the formula in ELD[^1]:

$$\log (\sigma_{TL}) \mid \log (K) \sim \mathcal{N}(a_{TL} \log (K)+b_{TL}, \hat{\sigma}_{TL})$$

$$\log (\sigma_r) \mid \log (K) \sim \mathcal{N}(a_r \log (K)+b_r, \hat{\sigma}_r)$$

We can use the K and distribution parameters obtained for each camera at different ISO levels as data points to fit a logarithmic linear relationship between them:

<p align="center">
<img src='../.assets/calib/log.png' alt='ICCV23_LED_LOGO' width='600px'/>
</p>

## calibration process

For the calibration process, you can execute all steps at once by directly following the code given in the main function, or you can perform each step separately according to your needs. These steps include selecting the positions of color blocks, calibrating the color blocks to obtain K, calibrating dark images to obtain other parameters, and fitting log(K) and log(variance).

## Acknowledgments

This code is based on the related works of ELD and PMN. We hereby express our gratitude to the authors and contributors of ELD[^1] and PMN[^2]!

[^1]: 1https://arxiv.org/abs/2108.02158

[^2]: https://github.com/megvii-research/PMN/tree/TPAMI