darktable icon indicating copy to clipboard operation
darktable copied to clipboard

Depth map masks

Open vallerelax-lab opened this issue 2 months ago • 15 comments

I am a big fan of Darktable masking but one type of masking is not available right now...

Depth map masks

Would be great if this type of masking could be integrated within Darktable in a future upgrade...

Kind regards,

Gilbert Despeghel.

vallerelax-lab avatar Oct 15 '25 16:10 vallerelax-lab

No RAW provide a depth map, so how to create a mask without any information being recorded?

TurboGit avatar Oct 15 '25 16:10 TurboGit

I mean depth masks as found in ON1 Photo RAW and Photoshop based on a grey scale...

Op wo 15 okt 2025, 18:48 schreef Pascal Obry @.***>:

TurboGit left a comment (darktable-org/darktable#19517) https://github.com/darktable-org/darktable/issues/19517#issuecomment-3407391753

No RAW provide a depth map, so how to create a mask without any information being recorded?

— Reply to this email directly, view it on GitHub https://github.com/darktable-org/darktable/issues/19517#issuecomment-3407391753, or unsubscribe https://github.com/notifications/unsubscribe-auth/BY2C3VIULJRREERO2IER32D3XZ3FFAVCNFSM6AAAAACJI3W7SSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBXGM4TCNZVGM . You are receiving this because you authored the thread.Message ID: @.***>

vallerelax-lab avatar Oct 15 '25 16:10 vallerelax-lab

https://youtu.be/56FxmpQlX-g?si=EA4N-cHa5K75ZQTS

Op wo 15 okt 2025, 18:54 schreef Gilbert Despeghel @.***>:

I mean depth masks as found in ON1 Photo RAW and Photoshop based on a grey scale...

Op wo 15 okt 2025, 18:48 schreef Pascal Obry @.***>:

TurboGit left a comment (darktable-org/darktable#19517) https://github.com/darktable-org/darktable/issues/19517#issuecomment-3407391753

No RAW provide a depth map, so how to create a mask without any information being recorded?

— Reply to this email directly, view it on GitHub https://github.com/darktable-org/darktable/issues/19517#issuecomment-3407391753, or unsubscribe https://github.com/notifications/unsubscribe-auth/BY2C3VIULJRREERO2IER32D3XZ3FFAVCNFSM6AAAAACJI3W7SSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBXGM4TCNZVGM . You are receiving this because you authored the thread.Message ID: @.***>

vallerelax-lab avatar Oct 15 '25 16:10 vallerelax-lab

I mean depth masks as found in ON1 Photo RAW and Photoshop based on a grey scale...

@vallerelax-lab What did you mean when you wrote that it was based on "grayscale"? Grayscale of what exactly? Where do these grayscales come from?

victoryforce avatar Oct 15 '25 18:10 victoryforce

This is what I mean...

https://youtu.be/56FxmpQlX-g?si=EA4N-cHa5K75ZQTS

Op wo 15 okt 2025, 20:30 schreef Victor Forsiuk @.***>:

victoryforce left a comment (darktable-org/darktable#19517) https://github.com/darktable-org/darktable/issues/19517#issuecomment-3407750756

I mean depth masks as found in ON1 Photo RAW and Photoshop based on a grey scale...

@vallerelax-lab https://github.com/vallerelax-lab What did you mean when you wrote that it was based on "grayscale"? Grayscale of what exactly? Where do these grayscales come from?

— Reply to this email directly, view it on GitHub https://github.com/darktable-org/darktable/issues/19517#issuecomment-3407750756, or unsubscribe https://github.com/notifications/unsubscribe-auth/BY2C3VLDHBEPXJC7N2GJSED3X2HDLAVCNFSM6AAAAACJI3W7SSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMBXG42TANZVGY . You are receiving this because you were mentioned.Message ID: @.***>

vallerelax-lab avatar Oct 15 '25 19:10 vallerelax-lab

No RAW provide a depth map, so how to create a mask without any information being recorded?

This is not true. Depending on model and camera settings, many smartphones embed a depth map. I believe iPhones always do it, while with my Pixel 4a I have to choose between that or some other feature.

Donatzsky avatar Oct 15 '25 20:10 Donatzsky

Ok, but then you'll agree that if it is on some smartphones it is a marginal use for Darktable where I suppose most of us are using real cameras.

TurboGit avatar Oct 16 '25 05:10 TurboGit

Oh, it's definitely not a high-priority task, but I could see some neat uses for it. For now at least, there's the workaround of extracting it with ExifTool and importing as a raster mask.

Donatzsky avatar Oct 16 '25 19:10 Donatzsky

I believe the author rather meant an AI tool which generates a depth map from the 2D image, which can be used for masking, like treating foreground and background individually, with a gradual mask between FG and BG. In my opinion this is incredibly hard, as it is impossible to reconstruct depth information from a 2D image. Most "AI" tools are just hallucinating the information based on training data, but can be very wrong in some cases. I think the example image in this capture one video is a quite easy case to reconstruct a depth map from, but I can imagine a lot of cases where this is not going to work well.

There is already some work in progress for supporting segmentation masks in darktable, which could be also used for such masking tasks (combine segment mask with gradient mask):

  • https://github.com/darktable-org/darktable/pull/18722
  • https://github.com/darktable-org/darktable/pull/18356

da-phil avatar Oct 17 '25 17:10 da-phil

Oh, it's definitely not a high-priority task, but I could see some neat uses for it. For now at least, there's the workaround of extracting it with ExifTool and importing as a raster mask.

I agree. Also, extracting an already existing (embedded) depth map is more realistic, in terms of effort to implement, than adding some AI tool to generate it from scratch.

da-phil avatar Oct 17 '25 17:10 da-phil

Thank you very much for your correct response. This is exactly what I meant.

Op vr 17 okt 2025, 19:22 schreef Philipp Lutz @.***>:

da-phil left a comment (darktable-org/darktable#19517) https://github.com/darktable-org/darktable/issues/19517#issuecomment-3416438804

I believe the author rather meant an AI tool which generates a depth map from the 2D image, which can be used for masking, like treating foreground and background individually, with a gradual mask between FG and BG. In my opinion this is incredibly hard, as it is impossible to reconstruct depth information from a 2D image. Most "AI" tools are just hallucinating the information based on training data, but can be very wrong in some cases. I think the example image in this capture one video is a quite easy case to reconstruct a depth map from, but I can imagine a lot of cases where this is not going to work well.

There is already some work in progress for supporting segmentation in darktable, which could be also used for such masking tasks (combine segment mask with gradient mask):

— Reply to this email directly, view it on GitHub https://github.com/darktable-org/darktable/issues/19517#issuecomment-3416438804, or unsubscribe https://github.com/notifications/unsubscribe-auth/BY2C3VP5V5VWYPRGV32WOT33YEQVFAVCNFSM6AAAAACJI3W7SSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIMJWGQZTQOBQGQ . You are receiving this because you were mentioned.Message ID: @.***>

vallerelax-lab avatar Oct 17 '25 17:10 vallerelax-lab

edit - added an example

Hi, Just adding a note: there’s a monocular depth model called MiDaS v3.1 (MIT-licensed, so GPL-compatible) that can generate depth maps from a single image: https://github.com/isl-org/MiDaS

I used it a bit in python to generate volumetric fogs on picture and it works pretty well (interiors, landscapes). It works locally and outputs a simple grayscale depth map that could be imported as a mask.

Just sharing in case it helps!

Here is an example: original image, depth map estimation, image with volumetric blur

Image

otto-link avatar Nov 11 '25 21:11 otto-link

To set some expectations on this feature: I don't believe any of the currently active devs is going to implement this, as they have different priorities. However I think as a first step, we can finish the work in this PR, which allows to load external raster masks into darktable. This means, generation of a depth map needs to be done in an external program and then used in darktable.

Depending on the progress of this PR, which is also going to use a ML model to generate semantic segmentation masks, we can think about a unified interface on how to connect ML models to darktable to generate segmentation masks or even depth maps. In the vkdt project @hanatos already integrated a couple of DNNs for denoising or even joint denoising & demosaicing. We'd also need to think how we store network weights and a workflow which should enable people to effortlessly import weights or even add training tools, such as in the vkdt modules mentioned above.

da-phil avatar Dec 05 '25 14:12 da-phil

Thanks for the update :) For inference, I'm aware of the ONNX exchange format which offers some runtime API for inference. The model mentioned above is for instance available as ONNX.

otto-link avatar Dec 05 '25 15:12 otto-link

fwiw vkdt has a non-neural haze-to-depth map estimation module: https://github.com/hanatos/vkdt/tree/master/src/pipe/modules/dehaze that may or may not work for your use case:

Image

hanatos avatar Dec 06 '25 10:12 hanatos