1. Home
  2. Docs
  3. Cameras for Raspberry Pi
  4. Native Raspberry Pi Cameras
  5. Lens Shading Calibration (Fix the Red Tint After Swapping Lens)

Lens Shading Calibration (Fix the Red Tint After Swapping Lens)

20
Before and after the calibration

What is the lens shading effect we are talking about?

Sometimes when you replace the stock lens of the Raspberry Pi V1 or V2 camera with an Arducam Lens, you will encounter a color issue where the outer side of the picture loos pink or magenta. That is a lens shading artifact, which is expected but can be solved.

It is expected because the default compensation is only valid for the stock lens of the Pi cameras, while different lens should have been compensated differently for their optical results. It can be solved because the file to alter the compensation – the lens shading table – can be overridden to match your own lens.

How should I tune the configuration file to match my lens?

Well, you don’t have to tune the compensation yourself because Arducam has already done the work for you. You just need to double check which Arducam lens you have on hand and know what the corresponding files you will be using.

Here is the matching relationship between the FoV, SKU and Part number of the mostly used Arducam lenses, and you will be referring to the FoV degree numbers in the first column for the target file.

FoV DegreesPart NumberSKU
10M2016ZH01LN001
20M2508ZH02LN002
40M2506ZH04LN003
45M2504ZH05SLN011
55M25360H06LN004
60M25360H06SLN012
65M40320M06SLN015
70M27280M07SLN013
80M27210H08LN005
90M40210M09SLN014
100M40180H10LN006
120M25170H12 LN007
140M25156H14LN008
160M30171H16LN009
200M32076M20LN010
Arducam lens matching relationship

How to use the Arducam presets for lens shading calibration?

Arducam has provided two methods to compensate the lens shading effect. The first is precompiled raspistill tools, and the second is pre-configured lens shading tables to be recompiled in your raspistill.c code. If you want to apply the compensation with raspivid, refer to the second method.

1. Use the precompiled raspistill tool

1.1 Download the customized Raspistill Tool

Arducam has provided tools for M12 lenses and CS-Mount lenses, and you can get the files here, or you can clone the repository.

git clone https://github.com/ArduCAM/NativePiCamera.git

1.2 Copy the file to the Pi Directory

1

Check the table of matching relationships above to find the target file in NativePiCamera/bin, then copy it to the Pi directory.

For example

If you are using Arducam M40210M09S (LN014), you can know from the table that its FoV on V1&V2 Pi cameras is 90 degrees. Therefore, you need to copy the raspistill_M12_90_lens to /home/pi path.

1.3 Enter the Pi Directory

cd /home/pi

1.4 Run the tool

Let’s assume that we are still using the last example with the M40210M09S (LN014) lens, you can run the following command for a preview.

./ raspistill_M12_90_lens –t 0

2. Override the lens shading table and recompile

2.1 Download the repository

The lens shading table is in the same repository as the above. You can skip it if you’ve already done this from the first method. The lens shading table is in the NativePiCamera/ls_table folder.

git clone https://github.com/ArduCAM/NativePiCamera.git

Now recompile the raspistill source code to correct the lens vignetting using the generated lens gain table data (ubuntu16 cross compilation)

2.2 Download userland source code

 git clone https://github.com/6by9/userland.git

2.3 Install cmake

 sudo apt-get install cmake

2.4 Rename and override

2

​​Rename the ls_table_M12_xx.h to ls_table.h and copy the file to the /userland/host_applications/linux/apps/raspicam path

3

Open the raspistill.c file add some changes to the code.

4
5
6

Then recompile:

7

Then you will get the new raspistill tool which is in the build/bin/ path

8

The expected results of the Calibration

  • M12 FOV:10°
10
  • M12 FOV:20°
20
  • M12 FOV:40°
40
  • M12 FOV:45°
45
  • M12 FOV:55°
55
  • M12 FOV:60°
60
  • M12 FOV:65°
65
  • M12 FOV:70°
70
  • M12 FOV:80°
80
  • M12 FOV:100°
100
  • M12 FOV:120°
120
  • M12 FOV:140°
140
  • M12 FOV:160°
160
  • M12 FOV:200°
200

Was this article helpful to you? Yes 1 No