The .dng format is a more compatible and efficient RAW format. If you need to exchange RAW files between different software, or if you need to do a lot of editing in the software, the .dng format is a good choice.
Table of contents
1. .dng format data and .RAW format data
.dng format and .RAW format are both digital camera raw data file formats. The .dng format is an open standard format developed by Adobe to solve the problem of incompatibility between RAW formats of different cameras. The .RAW format is a format developed by each camera manufacturer according to its own standards and is usually incompatible.
Both the .dng format and the .RAW format save the raw data of the digital camera sensor, including the pixel value of the image, exposure information, white balance information, etc. This information can be used by editing software to generate image formats such as JPEG and TIFF.
2. The difference between .dng format data and .RAW format data
3. Install the rawpy package
Use the following command to install the rawpy package
pip install rawpy -i https://pypi.mirrors.ustc.edu.cn/simple/
The installed look is as follows:
4. Read .dng format data code
import rawpy
import numpy as np
img_dng = rawpy.imread('data/archive/reno10x_noise/reno10x_noise/gray_scale_chart/RAW_2020_02_20_13_06_43_108/DNG_2020_02_20_13_06_43_108_1.dng')
pattern = img_dng.color_desc
print(f"CFA pattern: {
pattern.decode('ascii')}")
img_dng_dng = img_dng.raw_image.copy()
img_dng_dng = np.array(img_dng_dng)
print(img_dng_dng)
The .dng format data can be read through the above code, as follows:
5. Read .RAW format data code
import rawpy
import numpy as np
img_raw = rawpy.imread('data/Sony/long/00001_00_10s.ARW')
pattern = img_raw.color_desc
print(f"Bayer pattern: {
pattern.decode('ascii')}")
img_raw_raw = img_raw.raw_image.copy()
img_raw_raw = np.array(img_raw_raw)
print(img_raw_raw)
The .RAW format data can be read through the above code, as follows:
6. Summary
The above is the method and code for using rawpy.imread to read .RAW format data and .dng format data.
It’s not easy to summarize. Thank you for your support!