penguin

determining focus in lighttable

wouldn't it be great if you could judge sharpness of your images in lighttable mode? this mode is limited to small and medium sized thumbnails of your images, so we can deliver the required speed to browse a lot of them.

to tell whether or not you got the focus right during the shoot, we would like to look at the full resolution. the most you get out of lighttable mode will look like this:

image2

image1

which one is sharper?

if you're not using the embedded jpg thumbnail or if you have worked on the history stack, these thumbnails are actually processed through our image pipeline. so depending on what you did with the image, processing the full-resolution can take seconds if not minutes. we really don't want to do that for all visible images.

 

full-res embedded thumbnails

an average raw file stores quite a lot of thumbnails. often there is even a full resolution jpg to be found. couldn't we make use of that?

now displaying this thumbnail is quite useless (there is a secret backdoor in dt to do it, but i'm not going to talk about it), as the resolution is usually smaller than what you'd get from the raw, highlights will look different, there are differences in color management and basecurves. it's just different and if nothing else it confuses my perception of colors when looking at the developed raw after that.

so even if we don't want to look at the thumbnail, we can extract focus information from it.

 

how it works

i tried simple edge-detection filters, such as the ones used for in-camera focus detection in the excellent magic lantern firmware. since different lenses have different sharpness and high-iso might make these numbers noisy, dt uses a slightly different approach.

we do a two-scale decimated cdf 2,2 wavelet transform and use a threshold on the detail coefficients. the second scale is only computed if the first scale (the sharper one) doesn't yield any results. visually, these are displayed as red clusters (first scale, very sharp) and blue clusters (second scale, not quite as sharp).

to account for any cropping and lens or keystone correction potentially applied to the image, we transform the clusteres detected on the embedded jpg thumbnail through the image pipeline, as we do with drawn masks. that means you'll get sharpness clusters on the correct spot without processing the image.

how to use it

switch on the new gui setting plugins/lighttable/display_focus or indicate focus regions in the gui preferences dialog.

if you now select a picture in lighttable mode and press `z' to switch to full res preview, you should get something like

red blue

double checking in darkroom mode and zooming to 200% shows that the one with the red boxes is indeed sharper:

red_closeup

blue_closeup

 

where to get it

this code is currently in a branch `full-res-preview' and about to be merged into master, for release in the upcoming 1.4 release.

Attachments

13 thoughts on “determining focus in lighttable

  1. It sure looks like a very useful feature. Two wishes:
    – make it possible to filter images (e.g. to quickly get rid of unacceptably bad shots)
    – tune the algorithms; they are confused by many shots I tried them on (please send email for images if you need them).

    Thanks for the effort you put into DT, it’s coming along really nicely!

  2. As the feature is in git master in the meantime, I tried it. It is a very nice feature. As Kofa stated above, there are shots on which the algorithm spots the in-focus area very,very nicely, on others it marks areas in red boxes, which are “out-of-focus” or “less in focus”.

    Is there a chance that the algorithm takes into account where the in-focus area “should have been” – based on EXIF data? If the camera marks in the RAW file which AF sensor (PD) or sensor area (CD) the focussing was based on, this area could be analyzed with priority, and maked differently (i.e. a yellow box).

    • From a Sony A700 in “Sports” program:

      exiftool DSC01081.ARW | grep AF
      Focus Mode : AF-C
      AF Area Mode : Spot
      Local AF Area Point : Center <—-
      Priority Setup Shutter Release : AF
      AF Illuminator : Auto
      AF With Shutter : On

    • those focus fields are very vendor specific. ideas to show those have been around for some time. canon even stores the x/y coords in exif. i’m not sure i like the idea at all, but if i would go and implement it you can be sure it would only work for my camera and not for yours..

    • Yes, and if would then add support for my current cam, it wouldn’t probably work for my next …
      But seriously, it would of course require a community effort, same as it is with basecurves, color matrices, noise profiles, …

    • it works by taking the embedded thumbnail out of the image. if there is no thumbnail, it fails. that means to support non-raw file formats there is some coding overhead to work your way around that.

      i’m not really interested in jpg files, if anyone was to add support for it in src/common/imageio.c:65 (dt_imageio_large_thumbnail) it should just work.

  3. great function, but unfortunately it does not works for me in Darktable 1.4. Activated the right option in the preference, even restarted Darktable, but I didn’t get red nor blue zone…
    any idea ?