LED icon indicating copy to clipboard operation
LED copied to clipboard

以DNG格式导出,并包含源元数据,以便在RawTherapee、Darktable和Lightroom等外部RAW编辑器中使用。

Open FloBEAUG opened this issue 10 months ago • 2 comments

你好,你做得很好,我对你的作品供个人使用非常感兴趣。我想修改 image_process.py 脚本以输出包含去噪拜耳原始图像和源元数据的 DNG 文件,以便我可以在原始图像编辑器中打开它。 我修改了代码以针对我的 CR3 Canon 文件对其进行微调(效果很好),并且输出的 PNG 非常出色。但是,我想将原始文件保留在最后。 你认为这可能吗? 谢谢!

FloBEAUG avatar Feb 02 '25 10:02 FloBEAUG

您好!感谢您对LED的关注!

或许我可以尝试使用pydng与pyexiftool来帮助您将处理后的bayer图像重新保存为dng文件。不知道这样是否符合您的需求呢?

BTW, 如果我们的 LED 对您的项目有帮助,我们欢迎您给我们一个星标 🌟,这将是对我们进一步更新的巨大鼓励!

Srameo avatar Feb 04 '25 01:02 Srameo

我做了一些调整。

它并不完美,存在一些颜色管理缺陷(颜色矩阵未导入),但对我来说可以使用。如果你愿意,随时可以更新。

image_process.py:

import subprocess
from pidng.core import RAW2DNG, DNGTags, Tag
from pidng.defs import *
import json
import pathlib
def read_img(raw_path):
    exiftool_output = subprocess.run(["exiftool", "-json", raw_path], capture_output=True, text=True, check=True)
    tags = json.loads(exiftool_output.stdout)[0]
    white_balance = list(map(int, tags['WB_RGGBLevelsAsShot'].split(' ')))

    [...]
    return raw, raw_pattern, raw_packed, black_level, white_level, white_balance
def save_as_dng(rawImage, filename, bpp, bl, wl, wb):
    height, width = rawImage.shape
    r, g1, g2, b = wb

    # set DNG tags.
    t = DNGTags()
    t.set(Tag.ImageWidth, width)
    t.set(Tag.ImageLength, height)
    t.set(Tag.TileWidth, width)
    t.set(Tag.TileLength, height)
    t.set(Tag.Orientation, Orientation.Horizontal)
    t.set(Tag.PhotometricInterpretation, PhotometricInterpretation.Color_Filter_Array)
    t.set(Tag.SamplesPerPixel, 1)
    t.set(Tag.BitsPerSample, bpp)
    t.set(Tag.CFARepeatPatternDim, [2, 2])
    t.set(Tag.CFAPattern, CFAPattern.RGGB)
    t.set(Tag.BlackLevel, int(torch.mean(bl)))
    t.set(Tag.WhiteLevel, int(torch.mean(wl)))
    t.set(Tag.CalibrationIlluminant1, CalibrationIlluminant.D65)
    t.set(Tag.AsShotNeutral, [[g1, r], [g1, g2], [g1, b]])
    t.set(Tag.BaselineExposure, [[-150, 100]])
    t.set(Tag.Make, "Unset")
    t.set(Tag.Model, "Unset")
    t.set(Tag.PreviewColorSpace, PreviewColorSpace.sRGB)

    # save to dng file.
    r = RAW2DNG()
    r.options(t, path="", compress=True)
    r.convert(rawImage, filename)
def postprocess(raw, raw_pattern, im, bl, wl, output_bps=16):
    def postprocess(raw, raw_pattern, im, bl, wl, output_bps=16):
    im = im * (wl - bl) + bl
    im = im.numpy()[0]
    im = depack_raw_bayer(im, raw_pattern)
    H, W = im.shape
    return im
def image_process():
[...]
    bayer_result = postprocess(raw, raw_pattern, result, bl, wl, args.bps)
    output_name = os.path.join(args.save_path, pathlib.Path(raw_path).stem + ".dng")
    save_as_dng(bayer_result, output_name, args.bps, bl, wl, wb)
    subprocess.run(["exiftool", "-q", "-overwrite_original", "-tagsFromFile", raw_path, "-all:all", "-LensModel",
                        output_name])
[...]

它并不完美,存在一些颜色管理缺陷(颜色矩阵未导入),但对我来说可以使用。如果你愿意,随时可以更新。

FloBEAUG avatar Feb 04 '25 07:02 FloBEAUG