Introducing a new FOSS raw image denoiser, RawRefinery, and seeking testers.

played around and with help of claude.ai here a simple lua based solution with a lot of room for improvements (at least running on my mac)
rawrefinerlua.zip (7.5 KB)

prerequisites: having RawRefinery installed via python -m pip install rawrefinery so all dependencies are in a place known to the system.
RawRefineryCLI.py : stripped down from RawRefineryApp.py to be commandline only
raw-refinery.sh : simple shell script to keep lua call simple
raw_refiner.lua: modified ext_editor.lu for just one purpose

quick and dirty - but maybe a starting point for those who speak python and lua more fluent :wink:

3 Likes

for me it works:

pipx install rawrefinery
pipx runpip rawrefinery install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/rocm7.1

I have a AMD Radeon RX 7800 XT.

However, I’m not sure how fast it would be on nvidia :smiley:

edit: on second look: I think it does not use the GPU… I can see a CUDA device but the GPU seems to do nothing. I’ll check if I can figure that out…
edit: on third look it looks like Rocm is working correctly and I can use the GPU together with torch… Interestingly, the usage in nvtop is listed as graphics and not compute. But that may just be a rocm thing… But now I wonder, is it normal that the GPU does nothing 95% of the time when processing an image? nvm - it seems to be only like this when the preview is created. saving the image uses the GPU.

I think that I shouldn’t need to differentiate, as both backends seem to be called with torch.device(“cuda”). Can anyone with AMD and gpu verify that?

@reox @MStraeten @Terry

I love this idea. Good news, I’m currently working on the command line interface for RawRefinery, which might make it easier. I’ll also look at the Lua example you provided afterwards.

I hope to have the first CLI out today or tomorrow now that I’m back from visiting family.

2 Likes

Seems to work for reox above so it should be fine indeed

should just be cuda:

>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.cuda.get_device_name(0)
'AMD Radeon RX 7800 XT'
>>> torch.version.rocm
'7.1.1'

does this help?

1 Like

Hi all, I made a CLI version of RawRefinery:

I plan on making it also a backend for RawRefinery as well.

@MStraeten

Hey, I didn’t notice you already made a CLI version, I should’ve copied your work haha. In fact, I should steal some of your command line interface design choices (e.g. no-cfa being the default).

Has anyone tried building this on Distrobox? if so, what distro? I’m on an immutable operating system and cannot install the dependencies as there is no Flatpak or AppImage

by the way, amazing work, thank you :heart:

1 Like

I do

export HSA_OVERRIDE_GFX_VERSION=10.3.0

for my 6700 XT to identify as gfx1030. rocminfo shows correctly:

Agent 2                  
*******                  
  Name:                    gfx1030                            
  Uuid:                    GPU-XX                             
  Marketing Name:          AMD Radeon RX 6700 XT              
  Vendor Name:             AMD                                
  Feature:                 KERNEL_DISPATCH                    
  Profile:                 BASE_PROFILE                       
  Float Round Mode:        NEAR                               
  Max Queue Number:        128(0x80)                          
  Queue Min Size:          64(0x40) 

yet when I start rawrefinery I get in the terminal:

Must be in ['gfx900', 'gfx906', 'gfx908', 'gfx90a', 'gfx942', 'gfx1030', 'gfx1100', 'gfx1101', 'gfx1102', 'gfx1200', 'gfx1201'

Any pointers? Is it problematic that it’s “Agent 2”?

here the modified lua script to access the CLI - thanks to claude.ai :wink: :
rawforge_refinery.lua.zip (3.2 KB)

User Guide

Rawforge Refinery for Darktable

A Darktable Lua script that integrates rawforge Python processing for batch RAW image refinement.

Features

  • Batch process RAW files (CR2, CR3, NEF, ARW, DNG) using rawforge
  • Automatically imports processed DNG files back into Darktable
  • Preserves metadata by copying from in_file to out_file: tags, ratings, and color labels
  • Groups processed images with originals

Installation

prerequisite: pip install rawforge

  1. Copy rawforge_refinery.lua to your Darktable Lua scripts folder:
  • Linux: ~/.config/darktable/lua/contributed/
  • macOS: ~/.config/darktable/lua/contributed/
  • Windows: %LOCALAPPDATA%\darktable\lua\contributed\
  1. Enable the script in Darktable:
  • Go to Script module in lighttable view
  • in folder contributed select rawforge_refinery

Configuration

The module panel appears in both Lighttable and Darkroom views. Configure these settings:

  • Python Script Path: Full command to run rawforge
    • Example: python3 /home/user/rawforge.py
    • Or just rawforge if it’s in your PATH
  • Model Name: The rawforge model to use (required)
  • Device: Processing backend
    • cuda - NVIDIA GPU
    • cpu - CPU processing
    • mps - Apple Silicon GPU
  • Output Suffix: Text added to filename (default: _denoised)
    • Input: IMG_1234.CR2
    • Output: IMG_1234_denoised.dng
  • Extra Parameters: handle all further parameters
    • e.g. --cfa --tile_size 512 --disable_tqdm

Usage

  1. Select RAW images in Lighttable view
  2. Configure settings in the Rawforge Refinery panel
  3. Click Process Selected Images
  4. be patient since there’s no progress displayed in darktable
  5. Processed DNG files are automatically imported and grouped with originals

Notes

  • Skips files if output DNG already exists
  • All settings are saved between sessions
  • just tested on macOS
4 Likes

Is there actually a description of the different models somewhere? I may just have missed it :sweat_smile:

Thanks for the kind words!

There is a rough recipe to compile it with pyinstaller into an ELF file. I think it should be possible to make an app image from that.

However, the procedure is far from robust.

As for distrobox,

Can I include your script in the repository with the instructions? I would be happy to credit you.

yes of course - i just made a pullrequest for it to be taken into the darktable lua script set:

2 Likes

No, there is not, but I can describe them haha.

The denoise models all denoise images, but vary in the computational intensity. e.g. Super light is much faster for CPU, while heavy will be much slower, but may result in better denoising for very noisy images).

“Deblur” is a model that can remove light motion blurring.

“DeepSharpen” is a model that can perform sharpening and increase micro contrast. I’ve found it’s useful for increasing details after denoising.

The last two models are not perfected yet, so I haven’t focused on advertising them, but they are fun to play with.

2 Likes

Nice, I think this is a great solution.

Am I correct in assuming that the goal is to pip install it on a distrobox vm running on your OS?

I have not used distrobox, but I could try it out.

Hmm, I’m forgetting, is this raw refinery specific? e.g. if you run python in the terminal, and then run pytorch, can you use cuda?

Honestly, I should just include a test script in the repo to help with IDing the issue. I’ll try to do that later.

I don’t think it’s specific to rawrefinery. Was meant as a question to all amd users as I’m not used to using torch in any way

Have I configured this right. I am on Windows. When I run the script I get an error message and no DNG


you need to check darktable -d lua error logs. i haven’t run this on windows …
Maybe run python rawforge.py from commandline to check if that’s appropriate. At least on my mac the command rawforge is sufficient since all pip installed python stuff is in my path.

Modelname should be TreeNetDenoiseSuperLight