tuning automatic lens shading correction (ALSC) #597
-
I have a couple of questions about adjusting the automatic lens shading correction (ALSC). My camera sensor is sitting in the focal plane of an instrument. The illumination is green, so I have set Because of lens shading, the green illumination is not uniform across the focal plane, but falls off radially from the center. In the subsequent analysis that I do, it would be very helpful to correct for this, so that the average green level is uniform across the entire sensor. I believe that the ALSC part of the image processing pipeline should be able to accomplish this. However the current images, with the stock tuning file, show a distinct radial fall-off in average green levels. In reference to Section 5.9 of the Raspberry Pi Camera Algorithm and Tuning Guide, the goal should be that after ALSC, each of the 16x12 regions has the same average green value. Question 1: Question 2: Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 22 replies
-
You don't say what sensor you're referring to, but from your other questions I assume this is the HQ cam? You're right that you probably need to change the So certainly put the |
Beta Was this translation helpful? Give feedback.
-
Hi David, I had a look at imx477.json and also read Section 5.9 carefully. This left me with a couple of questions, because there is no clear connection between the Section 5.9 documentation and the entries in the rpi.alsc section of the tuning file. Based on the documentation, the goal is to determine three sets of weights lambda_i, where i is an index over a set of 16 x 12 = 192 points. (By the way, this array is shown in Fig 13, and at 16x12 already extends corner-to-corner. I don't think that it is 17 x 13 in size.) First question Second question Cheers, |
Beta Was this translation helpful? Give feedback.
-
Hi David, I had to focus on other things for a while, but I'm back at work on this code again. I wanted to package my "custom ALSC" in a way that ensures that by default (when picamera2 is used) the stock ALSC algorithm is used, but which permits me to enable "my" ALSC from within picamera2. Could you give me some advice about a good way to go about this? One approach is to extend the stock ALSC code to include my additions to it, and enable those via a picamera2 control call within my application. But if possible I'd prefer to leave the stock ALSC code in place and simply add my own routines to the .so library via some ALSC_custom version. Cheers, |
Beta Was this translation helpful? Give feedback.
-
It's certainly possible for people to implement and use their own custom control algorithms, we very deliberately designed it this way. Having said that, if you want to include the standard ALSC as part of that then I'm not sure what the best approach would be. One could just copy the code and add what you want, but the duplication doesn't feel great. Or could our implementation be used directly just by calling the switch_mode/prepare/process methods? Switching algorithms at runtime is another question. We can't really switch from one self-contained algorithm implementation to another on the fly, so you'd probably need an algorithm that actually incorporates everything, and then allows the switch. For this we'd need some kind of libcamera control to be available, which I'm sure they would agree to if we have good reasons. Can you remind me again what the scope of your changes is and what happens differently? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi, yes this is a tricky question. In general I'm not terribly in favour of putting in custom behaviour with custom switches, on the grounds that we might find ourselves acquiring ever more of these as time goes on and the whole thing becomes ever harder to maintain. Making a complete copy is one solution, though duplicating loads of code is never great. I wonder if there's a way forward that allows you to reuse the code that's there, and add to it? For example, one might derive a new ALSC algorithm class from our existing one and then, depending on certain settings, just call the base class methods, or do something different. For a solution like this I'd certainly be happy to tweak things in our implementation to make it possible, perhaps like making private members public, and so on. What do you think? |
Beta Was this translation helpful? Give feedback.
-
From a pragmatic point of view, what you're doing seems pretty reasonable to me. Switching between green/non-green pixels is fine, I expect you get a slightly weird colour temperature being reported, but I assume that doesn't matter! With libcamera there is a more general question relating to platform specific or indeed completely custom behaviour. It deliberately doesn't give you easy ways to "tunnel" though the standard API so that you can implement custom things. I think the official position would be to create a more generally meaningful control and then to add it to the full set libcamera controls. But then do we want every custom application in the future to do this? It's not clear to me. In the past we've "tunnelled" around the standard control API for things like custom tuning files. On that occasion we just defined environment variables, though files (or pipes or sockets, it's not so very different) might be better for things that don't happen only at initialisation time. You could use a memory file (iin /dev/shm) to save going out physically to the SD card (you may be already of course!). |
Beta Was this translation helpful? Give feedback.
You don't say what sensor you're referring to, but from your other questions I assume this is the HQ cam?
You're right that you probably need to change the
luminance_strength
. You'll have to edit this in the tuning file because libcamera has no API for this (it's specific to the Raspberry Pi platform). Generally I've found the stock lenses that we supply for the HQ cam do show some vignetting (though not strong compared to the smaller camera modules), though it will also vary with the lens.So certainly put the
luminance_strength
value in the file back up to 1.0, but you may also find you want to measure a table for yourself if this isn't sufficient. I would hope the table is fairly obvio…