Pete6
Posts: 88
Joined: Sat Nov 24, 2012 4:02 pm

Getting the maximum out of the raspi-cam 2 in NOIR darkness

Mon Mar 23, 2020 3:35 am

I'm an amateur astronomer. I am using a raspi-cam2 (IMX219 sensor) to take images of the night sky once a minute via a NOIR lens.

raspistill is used to take an image once a minute. I am looking to get the maximum out of the camera. Here are my settings

Code: Select all

Twilight="-ISO 600 -hf -awb greyworld -n -ex auto -w 800 -h 600 -tl 60000 -t 2147483647 -o file.jpg"
Daytime="-ISO 80 -hf -awb greyworld -n -ex auto -w 800 -h 600 -tl 60000 -t 2147483647 -o file.jpg"
Nighttime="-ISO 800 -hf -awb greyworld -n -ex night -ss 6000000 -w 800 -h 600 -tl 60000 -t 2147483647 -o file.jpg"
These arguments are passed to raspistill at appropriate times of day. The Daytime and Twilight settings work fine. My problem is with the nighttime setting. It just cannot capture enough light to see the stars.

I am considering replacing the camera but before I do does anyone have a better set of raspistill for use in unlit night time situations. I do not care about colour.

Thanks
My favorite programming language is a soldering iron.

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

Re: Getting the maximum out of the raspi-cam 2 in NOIR darkness

Mon Mar 23, 2020 11:20 am

The v2 camera module can go up to 10sec exposure times, so that can be increased.
If you're wanting to force the analogue gain, then you're better off using -ex off -ag 8.0 (can't recall what the max is, suspect x12.0). Add -dg 2.0 for x2 digital gain as well, but that'll increase the noise too.

Fundamentally you can't beat the laws of physics - if the sensor can't collect enough photons from your source then you will see everything as black.
There are denoising and defective pixel algorithms active which may be working against you if you're trying to detect very small dots of light. A search should turn up further info on those.
You're also downscaling to 800x600. The 8Mpix of the sensor is therefore combining pixels, so the dot that may be one or two pixels at 8MPix is being merged with probably 14 others which aren't your dot.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Pete6
Posts: 88
Joined: Sat Nov 24, 2012 4:02 pm

Re: Getting the maximum out of the raspi-cam 2 in NOIR darkness

Mon Mar 23, 2020 3:29 pm

Thank for your reply. I have done what you suggested with the arguments. Now I'll wait for night and see what happens. This is iterative. Make changes, look at results. Repeat.

The raspi-cam sensor is quite good but there are obvious limits. My telescope astronomy camera cost over 2000 quid so it is slightly better...

There is a technique that I can use called stacking. I use this for taking planetary images. I'll take 2000 images of say, Saturn so I have a "stack" of similar but slightly different images. Software then reduces these to a single image. Of course I do need photons on silicon for this to work and that is my problem here.

I can obviously just buy a "better" camera but I'd like to give the IMX219 a last chance largely because I believe from its specs that it can do what I need. It's right on the edge though.
My favorite programming language is a soldering iron.

Pete6
Posts: 88
Joined: Sat Nov 24, 2012 4:02 pm

Re: Getting the maximum out of the raspi-cam 2 in NOIR darkness

Tue Mar 24, 2020 12:42 am

This now works. Thank you for your help.

Code: Select all

raspistill -ISO auto -hf -awb greyworld -ex night -ss 10000000 -w 800 -h 600 -tl 120000 -t 2147483647 -n -o pic.jpg 
The main problem was that I had and still do not have access to the HDMI port. It's on the roof. This meant the only way I had to test was the 1 pic per minute I had told the camera to take. Wellll....

The above string takes 1 minute and 40 seconds from hitting <Enter> to getting the prompt back. That was most likely the problem. I'm using SSH here so I still cannot see the result. So I copy each test image to my desktop using WinSCP and I start to get meaningful images.

I'm still fiddling with the settings to get them where I want and I have now set raspistill to take a pic every 2 seconds and it is working.

Having carefully read the specs, I was always pretty sure that the IMX219 was up to doing this job. Now I could do with fewer clouds and some twinkly bits in the sky.

Question: Setting ISO and exposure to auto gives very good results. How does the IMX219 / raspistill / Pi know enough about an emerging image to adjust its sensitivity and exposure during an image take?

This set of arguments works even better:

Code: Select all

-ISO auto -hf -awb greyworld -ex off -ag 10.0 -dg 2.0 -ss 10000000 -w 800 -h 600 -tl 120000 -t 2147483647 -n -o
but I still need clear skies to test fully. Thanks.
My favorite programming language is a soldering iron.

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

Re: Getting the maximum out of the raspi-cam 2 in NOIR darkness

Tue Mar 24, 2020 10:50 am

The auto exposure/gain algorithm has 3 degrees of freedom - exposure time, analogue gain, and digital gain. (Technically aperture as well should you have a controllable lens).
It has 2 main controls into it - ex to suggest an operation profile, and mm to provide a biasing around the image. You then have a further control ISO to restrict the gain profile in a slightly dynamic way (it still allows minor compensation to work within flicker avoidance modes).

There are then 3 overrides to lock each of the degrees of freedom - ss to fix exposure time, ag to fix analog gain, and dg to fix digital gain. If the algorithm is still running and has any degrees of freedom left, it will use those to try and produce nicely exposured images.
In your command line, you've fixed all 3 degrees of freedom, therefore the -ex and -ISO parameters will be doing nothing.

The algorithm is looking at image statistics gathered across the image which give accumulate the pixel values within a region. As the size of the region is known, you therefore have an average intensity of the region by dividing it by the size. There are reasonably defined heuristics for what average intensity will look good.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Pete6
Posts: 88
Joined: Sat Nov 24, 2012 4:02 pm

Re: Getting the maximum out of the raspi-cam 2 in NOIR darkness

Tue Mar 24, 2020 1:42 pm

Thank you very much for that excellent and complete explanation. I shall try my best to use raspistill arguments that allow as much automatic control as possible. I am still very much feeling my way with this little project although I now have a feeling that I can see how it will look in the end.

Once I have finished my AllSky Raspi-Cam I shall make the software and a listyof hardware needed available for free to anyone who wants it. I'm retired and currently in self-isolation quarantine so this is a useful distraction.

Thanks very much for your help and insight.
Pete
My favorite programming language is a soldering iron.

Return to “Beginners”