6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5808
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Custom lens shading tables

Sun Jun 10, 2018 7:25 pm

drich wrote:
Sun Jun 10, 2018 5:51 pm
@6by9, currently my tool can import the ch1-4.bin files, are you OK by any chance to let me integrate your code (and credits you of course), allowing me to simply open JPEG-RAW images ?
Feel free. I'm all for people improving tools.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Sun Aug 19, 2018 4:17 pm

Hi!

I also would like to override the lens shading table, because we have to use a custom lens with the picamera in our project.

I've read that I have to use a special version of the Raspicam.c.

My program has written in Python, and I'm using the Picamera class to show the preview of the camera, take pictures, record video, change the settings of the camera.
Is it possible to overwrite the lens shading table if I'm using the picamera this way?
Could you give me some hint how should I start?

Thanks in advance!

Best Regards,
Zoltán

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5808
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Custom lens shading tables

Mon Aug 20, 2018 8:47 am

zbarna wrote:
Sun Aug 19, 2018 4:17 pm
My program has written in Python, and I'm using the Picamera class to show the preview of the camera, take pictures, record video, change the settings of the camera.
Is it possible to overwrite the lens shading table if I'm using the picamera this way?
Could you give me some hint how should I start?
You'll need to add support to the PiCamera library.
...
Actually it looks like someone has done that work already - https://github.com/waveform80/picamera/pull/470. I'm guessing waveform80 is busy on other things at the moment so it hasn't been merged. You'll have to build the updated library for yourself (instructions at https://picamera.readthedocs.io/en/late ... pment.html).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Mon Aug 20, 2018 10:01 am

Ah okay it's clear, thanks!
I'm going to try it! :)

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Mon Sep 03, 2018 7:56 am

Hi!

I successfully changed the lens shading tables in the picamera python module with the help of the link you posted above.

I tried a lot of different calibrator, and I reached the best result with this one:
https://github.com/rwb27/openflexure_mi ... penloop.py
It works similar way like 6by9's solution.

With this calibration, the color shading issue went away if I put white or black thing in front of the camera, but with other colored things it comes back :( .

Here you can see sample pictures (name of the picture tells the real color of the item):
https://drive.google.com/drive/folders/ ... kGH-ooF0WG

Could you give me some hint? Why does it work with black and white things, but if I put a red or yellow item it can't handle it.

Thanks in advance!
Best regards,
Zoltán

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5808
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Custom lens shading tables

Mon Sep 03, 2018 10:01 am

zbarna wrote:
Mon Sep 03, 2018 7:56 am
Could you give me some hint? Why does it work with black and white things, but if I put a red or yellow item it can't handle it.
Not off the top of my head.
There is an algorithm normally running to try and automatically adjust the lens shading tables as the modules aren't calibrated on the production line and there is always a small amount of variation, but that should be disabled with a custom table.
The fact that black and white comes through normally would imply that your tables are correct - there is no monochrome element in the sensor, only red green, and blue pixels arranged in the Bayer pattern. White balance would have the potential to interfere slightly as it alters the red and blue pipeline gains, but that is after lens shading correction and relies on lens shading to have been dealt with already before the statistics that it works from.

I'll try to find a few minutes to give it a whirl myself again.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Tue Sep 04, 2018 6:39 am

Thanks for your time!

I hope that we are very close to the solution :) .

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5808
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Custom lens shading tables

Tue Sep 04, 2018 1:00 pm

Running it myself with a debugger, the lens shading table appears to be correctly set based on the table passed in. I'm therefore unsure as to how come you're seeing such variation.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Tue Sep 04, 2018 3:40 pm

I don't understand what's happening with my camera.
This is my code with the modified python picamera module which can set the lens shading table:

Code: Select all

from picamera import PiCamera
import numpy as np
import time

with PiCamera() as cam:
    lst_shape = cam._lens_shading_table_shape()

npz = np.load('/home/pi/LensShadingTest/lens_shading_table.npy')

with PiCamera(resolution=cam.MAX_RESOLUTION, lens_shading_table=npz) as cam:
    cam.start_preview()
    time.sleep(600)
I create the lens_shading_table.npy with the calibrator.

With this code the lens shading table changed, because if I put a white paper in front of the sensor the lens shading issue went away.
I also tried to set the awb_mode->'off', but it didn't help me :S .

I will make a try with your raspistill.c, maybe the problem is in the modified picamera python module :S .

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Wed Sep 05, 2018 7:22 am

Hi!

I converted my lens shading table from the npz to the ls_table.h, built a new instance from the raspistill.c, and I got the same result. With white and black colored items the vignetting issue went away, with yellow, red or other colored items it came back.

I think this picture is very interesting. Here in the background it's a black item, and front of it a yellow colored item:
Image
On the right side it's correct where the color is black, but on the left side it should be yellow, but it isn't.

Here you can see the colors in the real life:
Image

I talked to the rwb27, who implemented the lens_shading change for the picamera module and the lensshading recalibration I used. You can read his answer here:
https://github.com/waveform80/picamera/ ... -418532710.
His answer sounds reasonable, but in this case we cannot solve this problem with just calibrate the lens shading this way.

Could you suggest something, or what should I do now? :S

Thanks in advance!
Best Regards,
Zolán

drich
Posts: 23
Joined: Tue Jul 28, 2015 7:36 pm

Re: Custom lens shading tables

Wed Sep 05, 2018 8:28 pm

Looks like the problem I'm facing when white balance changes.
Can you try with fixed AWB gains ?

zbarna
Posts: 15
Joined: Mon Apr 23, 2018 10:16 am

Re: Custom lens shading tables

Thu Sep 06, 2018 6:57 am

Yes, I tried to set the awb_mode->'off', but it didn't help me. :(

Return to “Camera board”