Are there tools to tell me if a raw file is clipped from the CLI?

I do most of my culling in geeqie, which helps me keep my darktable library nice and clean.

There are times, however, where I import two of the same composition that have slight different exposures into darktable to see if the file has any clipping.

It’d be nice if I could move that check into geeqie, and I could easily script something in bash, if only I knew what tool to use.

I don’t need to visualize the clipping or preview the image at all, just something that says “this is clipped” or “this is not clipped” would be plenty.

1 Like

What about Hraw? GitHub - lightful/hraw: Hacker's toolkit for image sensor characterisation

In Windows it is a drag and drop feature to check how many % that is clipped. In Linux I use the terminal.
$ dcraw -E -4 -j -t 0 -s all IMG_9106.CR2
$ ./hraw clipping -i IMG_9106_0.pgm -v

If you shoot Canon with ML support you can get the clipping feature already in camera.

2 Likes

Yup, that’s easier than what I was thinking of.

I was unaware of something like this existing directly, but it’s something I could probably whip up in a few minutes using rawpy and starting from one of my existing scripts.

I was thinking libraw and C++… :crazy_face:

I would use dcraw and ImageMagick, as I am most familiar with those tools. Windows BAT script:

%DCRAW% -d -D -t 0 -o 0 -h -4 AGA_3443.NEF

%IMG7%magick AGA_3443.ppm -alpha off -separate +append -threshold 16382 -format %%[fx:mean] info:

This returns a floating-point number, such as “0.0170776”. This is the proportion of pixel values that are greater than 16382. My camera (Nikon D800) records a maximum value of 16383. So this image has nearly 2% of the values at the maximum, which is more than I usually accept.

4 Likes

I am wondering if a more efficient method would be to grab something from the metadata and skip outputting a temp file and accessing it.

As far as I know, no metadata records whether any data is clipped, or at the maximum posible value.

The fastest solution would be a custom program written for the libraw (or similar) library. No need for demosaicing or a temporary file; just read the pixel data, and count the number of pixel values that are at the maximum. (Or count the number of pixels that have any values at the maximum, which isn’t the same thing.) Divide by the number of pixels to get the proportion that are at max.

EDIT: The above paragraph is somewhat naff. If we haven’t demosaiced, then every pixel has only one value, of course.

The program could accept multiple input raw files, and determine the one with the “best” exposure. This isn’t as easy as it sounds: most of my photos contain specular highlights that have blown, and I don’t care.

Better still, the program could read all the raws from a day’s shooting, figure out the sets of photos are like others except for exposure, and toss the bad ones from each set into the bin.

Besides specular lights, I could imagine bad pixels being an issue too.

1 Like

Libraw has a cli tool (or sample) ‘4channels’. It probably works different for xtrans camera’s (or not at all) but it writes 4 pgm files for the 4 channels in the Bayer data , raw with no white balance and gamma and black subtraction and such.

Tools like imagemagick or vips can tell you the maximum value your camera can record (not the same for every camera ) . The white points per channel for your camera are in libraw / dcraw / other OSS raw converter source code . Maybe exiftool can even extract it from the metadata. I believe the ‘just show me info do not process’ mode from the libraw dcraw emu shows you this.

I would parse the max from vips output, or even have imagemagick write a ‘clipped’ or ‘safe’ depending if the max value is in your file.