Smartphone DNGs and lens shading

I recently got a Pixel 4a and have been trying to figure out how to process the raw DNGs from the camera app.

The camera suffers from lens shading: vignetting that’s different for each color channel. The effect is noticeable - if I take a picture of a white surface, and white balance the center so that R=G=B at that point, then at the edges R < G and R < B. The radial vignetting model of lensfun doesn’t work to correct this - it has to be done before demosaic and it may also not be symmetrical if the optical image stabilization has moved the lens off center. It also varies with the focus distance.

The Android OS provides a lens shading map to correct it, which gets embedded in the DNG as GainMap opcodes within the OpcodeList2 tag.

Currently, ART is the only OSS raw converter that supports the GainMap. To enable it, in the Raw group turn on “Flat-Field” and select “Embedded in metadata”.

I started looking into how to add it to rawspeed / darktable but haven’t made much progress yet.

I’m experimenting with a quick and dirty workaround to process these files with the GainMap applied, in apps that do not support it yet. The raw2dng app compiles on Linux and includes the Adobe DNG SDK, so I used a fork of that as a starting point and added a new script dngpreprocess.

It takes a dng from the Google Camera app, loads it, applies the first few steps of processing, and writes it back out as a dng. It subtracts the black levels, converts from integer data to floating point scaled from 0 to 1, applies the GainMap, and writes it out as a floating point dng, still mosaiced. The resulting files seem to work with darktable, RawTherapee, rawproc, and Filmulator.

It doesn’t keep the preview image from the input dng. I couldn’t figure out a way to copy it from the input dng to the output dng, and when I tried to copy the code that generates the preview image from raw2dng it crashed.

There is also an option to replace the embedded camera profile with a dcp file. This may be useful with third party camera apps, which get a possibly questionable camera profile from the Android OS on the Pixel phone and write it to the dng, to replace it with the different profile used by the Google Camera app.

7 Likes

In my case, it happens on miui camera, google camera and lightroom’s camera .

I’ll have to check that out in art…My dirty workaround in DT has been to use the lens correction profile for the Huawei P10. I applied it one time just for fun as I too notice the strong vignette on my pixel 3aXL. It doesn’t seem to correct the image too badly so I leave it at that and it often takes care nicely of the vignette. Also manually I think the art vignette slider controlling fall off in art helps. You can just slide that a bit and nicely relieve the dark corners…neither is likely the best solution but things look better…

This is great information. I had tried the lcp file from adobe as they have one for the 3a but it only contains distortion corrections it appears at least when I tried it in ART that seemed to be the case. One other quick question. I have an issue currently. If i zoom and save raw and jpg my dng is treated like the the jpg almost using a digital crop on it so my dng files are small and low res often lmb and cropped to the zoom. They will actually crash in DT and there is no preview. If it don’t zoom all is fine I get a full res DNG that is around 13MB in size…have you seen this at all on your phone or heard of this. I tried to contact Google but that is pretty much spitting into the wind…

I also get the cropped DNG when I zoom in with Google Camera on the Pixel 4a. I zoomed in to 7x and the file is 432x576, exactly 1/7th of a full res DNG which is 4032x3024. But mine does have an embedded jpeg preview, and it does open successfully in ART and Darktable master (latest version built today).

So the app is messed up

If you use open camera or hedge cam they work properly. You get the full raw. But even that is not Straight forward as those dng have a tiff preview or maybe no preview just the tiff in a dng container…

I have tried to get an answer from Google but nothing…clearly their app is broken and I think it worked when I first got the phone

The difference is that Open Camera (and most other third party camera apps) just captures a single raw+jpeg frame and saves that exactly as it came from the camera. The Google Camera app captures a burst of multiple raw frames, aligns and stacks them, and creates the dng from that. So I would assume that it’s probably cropping the individual frames before it stacks them.

Actually for sure they don’t have the math to match GOOGLE but they have Noise reduction modes and HDR modes that let you save source raw file frames so you can combine or process them yourself…You can also save multiple raw files for exposure bracketing or focus bracketing… I must say I can’t attest to how good it is or is not as I don’t do much of that image fusion processing.

If google has to crop those files to do its math or merging so be it but it should still save a raw file that is full frame full res even if you are shooting with zoom. The jpg file will of course be the digital crop but the raw should not be…The whole reason for the raw is you might want to recompose your image and crop differently and currently that is a no go with the way google is treating raw capture with zoom.

This will be fun to try I will just have to try to figure out how to compile and run it… :slight_smile:

Another Pixel 4a owner here. Oh @paolod , you saved me from a lot of suffering! Thank you!!!

1 Like