Question: How do I set a custum white balance of the NoIR modulo cam?

LaPa is asking a question about pi-camera: Subscribe to answer questions on this topic

LaPa asked on December 03, 2015 21:53
5,063 | 0 answers | #12476


What I want to do

I'm an agronomist, I'm going to make a IR RaspiCam to do an IR Timelapse in greenhouse. I want add same sensors (temperature, moisture, soil moisture) at the IR Raspicam in order to link environmental condition to Health of the plant.

My attempt and results

I just took some (BAD) pictures as IR test

Questions and next steps

Hi! I'm going to take same IR pictures by NoIR modulo cam and blue filter (Roscolux #2007: Storaro Blue) in order to measure the health of plants. To take a Picture I'm using "Raspistill". According to this information https://publiclab.org/notes/warren/08-15-2013/white-balancing-a-canon-camera-for-infragram-photography I need to set white balance pointing a deep blue surface before take a IR picture of the plants. I didn't find any custom white balance command in the list of commands of Raspistill. How do I set a custom white balance?

Thanks in advance

best regards

Why I'm interested

1) Learn more about IR Images of the plants 2) to identify by IR Images of the plants best of growing condition or the moments of the worst health of the plants during their growth 3) to use IR Raspicam on aerostatic baloon



25 Comments

LaPa,

The custom white balance procedure you refer to works only for certain cameras. A year ago it was not possible to set a custom white balance on a Pi camera, and I have not heard that this had been implemented. So it might not be possible to set a custom white balance. That means it probably will not be possible to compute NDVI directly from the values in a photo taken with a Pi camera. It might be possible to adjust the values in the photo, but I have not had any success doing that with other cameras.

If you use two cameras, a Pi Camera and a Pi NoIR, custom white balance is not required.

Another approach will be to include calibration targets in the photo you take and use the new calibration capability of the Photo Monitoring plugin for Fiji to compute NDVI from your photos.

There is a discussion related to this here: https://publiclab.org/notes/warren/10-27-2011/video-tutorial-creating-false-color-ndvi-aerial-wetlands-imagery#c12966

Chris

Reply to this comment...


hi,

Did you trying this with picamera ? https://picamera.readthedocs.org/en/release-1.10/api_camera.html Here there are some possibility to parameter white balance with the "awb_gains" & "awb_mode"

Actually i'm trying to do more or less the same thing with raspberry.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Thanks Erwan,

It looks like awb_gains allows the red and blue channels to be adjusted relative to one another which is just what is needed. However, the adjustment apparently applies to auto white balance not to a fixed white balance. So you can make the red channel brighter (which you would want for a blue filter), but the camera will continue to adjust the white balance for each photo. So that could probably produce better photos for converting directly to NDVI using a red or blue filter. But the results could vary with each photo, so NDVI values could not be compared among different images.

Chris

Reply to this comment...


What do you think about this way to proceed?

https://www.raspberrypi.org/forums/viewtopic.php?p=856005#p856005

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


It is not clear that the other respondents at the Pi forum understand what you are asking about. Using awb_gains will allow every photo to exaggerate the values in the red (or blue) channel. I assume that the camera continues to use automatic white balance (AWB) and then also modify the values based on the awb_gains parameters. This is potentially a very good feature for using the Pi NoIR with a filter to capture photos that can each be converted to a facsimile of NDVI. However, if the AWB algorithm continues to adjust for every photo, the ratio of blue to red could vary among photos in unpredictable ways. For example, AWB will modify the ratio of blue to red if the background color (behind the plants of interest) differs between two photos. AWB will modify the ratio of blue to red if the sun goes behind a cloud. AWB could modify the ratio of blue to red if the camera angle changes relative to the sun or light source. So two photos of the same plants could have different red and blue values and therefore different NDVI values. This is not ideal, but awb_gains will probably allow better results than AWB alone or one of the white balance presets (sunny, tungsten, etc.). It would be very interesting to see a comparison of results.

The problem of variable lighting color affecting the balance of red to blue also applies when a custom white balance is done with a Canon PowerShot. In that case, the camera always applies the same adjustment to each photo, but if the external lighting color changes, the ratio of red to blue in the scene and also in the image of plants will change. (If only the background color changes, the red:blue ratio in plants will not change.) So even a custom white balance does not offer sufficient control to get consistent NDVI results unless the photo scene is carefully controlled.

This is why a calibration procedure is required to get reliable results. This requires that targets of known reflectivity in the visible and NIR be placed in the photos and then that a procedure be done to adjust the red and blue values in all pixels based on the red and blue values in the pixels of the targets. The calibration procedure does not solve the other problem with single camera NDVI systems that at least one of the channels will capture a mix of visible and NIR light. The proportion of NIR light contaminating the visible channel (or vice versa) can be estimated and accounted for (as Ned Horning's calibration procedure allows), but that assumes that the proportion is the same in every pixel. I assume it will vary a lot from pixel to pixel, so it is not clear how effective the VIS/NIR-mixture fudge factor will be.

So the only way to solve both problems is to use two cameras, one for visible light and one for NIR, and put calibration targets in photos from both cameras. The potential value of doing this with Pi cameras is that the Pi could trigger both cameras, align the two photos, and produce an NDVI image on the fly. I don't know whether the Pi is powerful enough to do this, and the calibration part might require some human intervention.

Chris

Reply to this comment...


Actually I don't know if it is possible mount two modulo cam in 1 Raspberry because it has just 1 slot to mount a modulo cam. I'll find out more about this.

Reply to this comment...


anyway I try awbg. I wrote in the terminal "raspistill -awb off -awbg 0.88,0.97 and I took a picture of the tester and a two plants. The light was natural and cloudyThat is the result. that make any sense for NDVI? image0023.jpg

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


That orange color of the leaves is promising. It should be even oranger. If you can put the plant in brighter outdoor light and take two photos -- one with awb_gains and one without, or try different parameters, then we can compare to see if it is working.

Some experiments with other cameras (not Pi cameras) suggests that cameras with CMOS sensors instead of CCD sensors work better as NDVI cameras if red filters are used instead of blue filters. It will be good to see results from a Pi cam, which is CMOS.

Reply to this comment...


Thank you cfastie, I seem that your post encourages me to keep on this way; I ask confirmation about this. Do you have any idea how to modify the parameter of -awbg (I used -awbg 0.88,0.97) to obtain the colour of the leaves more orange than the leaves of my previous photo?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


At the moment I took a photo two plants in sunny light. But I didn't manage to take another without gain because it became cloudy :(.

Is it possible transform this photo in NDVI photo. Could it have a meaning?

2PlantsInSunnyLightAwb097088.jpg

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Those basil leaves should not be the same color as the flower pot. They need to be more orange. To get NDVI values in the appropriate range, the values in the red channel should be several times greater than the values in the blue channel. Here is a typical photo from a CCD camera with a blue filter:

PoGrHist.JPG

The histogram for one leaf (marquee) shows the red channel being well separated from the blue channel. Below is a histogram for your basil leaf.

BasilHistogram.JPG

Below is an NDVI image from your photo.

NDVI_Fiji_stretchNIR.JPG

NDVI values are very low (around 0.2) instead of near 0.3 to 0.6. They are also not different from the flower pot.

To get better separation between the red and blue values, red has to be exaggerated more. So I guess the red value in awb_gains has to be farther from the blue value.

I don't know if it is possible to get that orange color with the NoIR camera and a blue filter.

Reply to this comment...


Hi Chris thank you for the suggestions! Do you think would it be a good idea take a set of photos (NoIR camera + blue filter) of the plant gradually increasing the gain of the red and gradually decreasing the gain of blue? After of this I'll check those photos by Gimp to verify the separation of red and blue channel. I could post same results here.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


LaPa, yes that would be very useful. It would also be useful if someone could do that with a red filter on the NoIR. Blue should be exaggerated when using a red filter.

Reply to this comment...


ok, i have to solve some problems of remote link of the Raspberry before taking other photos. And, of course, I have to buy a red filter because they sell the NoIR Pi camera just with a blue filter.

Reply to this comment...


hi. I have a question. when I set a black paper or black thing in custom white balance, and then i take a photo, why my photo become a green photo?PLEASE help me!!!!

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


Black surfaces do not reflect much light, but they do reflect some. Some black surfaces might reflect more green than other colors, and other black surfaces might reflect less green. If the camera sees less green during the custom white balance procedure, it will exaggerate green in all the photos it takes using that white balance setting.

Reply to this comment...


this green photo don't Relevance to Bayer pattern Mr. @cfastie ?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


The Bayer filters determine how wavelengths are separated into the three color channels. This is how the camera can sense the balance between the three colors. To produce a color jpeg photo, the camera adjusts the balance based on the white balance setting.

Reply to this comment...


Hi, I'm here again! I shoot a set of pictures by NoIR modulo cam and blue filter. I tryed finally different white balance. The photo that I post is one of that set. I shoot it with the command line "raspistill awb off awbg 1.28,0.57 test128057.jpg". This photo of 3 plants in the sunny lihgt has, in leaves, the red and blue channel well separated in the histogram and the leaves seem as orange as in the photo that Cfastie posted as model. Could this photo have a meaning in NDVI? [test128057.jpg]

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


That looks promising. I guess that PiCamera module is a useful tool. I think that photo is a little too yellow. The blue values for foliage are very low (mostly < 30) and the red values are very high (often > 200). Many leaf pixels have a NIR:VIS ratio greater than 8:1 and NDVI computes to 0.8 or higher. If healthy foliage has a NIR:VIS ratio near 3:1 then NDVI will compute to 0.5 which is more reasonable. So different values for awb_gains might be called for. Exposure is also important, so try to take photos with foliage that is not over exposed.

Reply to this comment...


Here is the range of NIR:VIS ratios for NDVI values between 0.2 and 0.8.

tuples1.JPG

Reply to this comment...


I'll try to get blue > 30 and red < 200 changing the gain. At the moment I do not know how change the exposure. May be I have to read better the raspistill documentation.

Reply to this comment...


HI, What do you think about my last test? NoIR modulo cam+blue filter, WBgain red = 0.88 and WBgain blue = 0.57 test088058.jpg

Is this a question? Click here to post it to the Questions page.

Reply to this comment...


That looks pretty good. With the defaults in the photo monitoring plugin, the plant leaves have an NDVI value around 0.3. We don't know what the NDVI values should be for those leaves, but that's in the right range.

It will be interesting to learn how consistent the results are among different photos. The camera is apparently using automatic white balance for each photo, and it probably uses the entire scene to make the decision. So if you zoomed in on just the plants, the result could be different.

Figuring this out is a great contribution.

Thanks, Chris

Reply to this comment...


I'm happy for this my first step in NIR and NDVI photograph! Maybe you know but ..... 1) I use not a real camera but a computer board (Raspberry Pi) + solar battery pack and equipped with IR modulo cam + blue filter. 2) Raspberry Pi has linux based OS Raspbian 3) I use a line command software (Raspistill) to shoot a photos.
4) The camera use automatic white balance for each photo as default but the photos that I posted had no automatic white balance but a custom white balance that I set by line command of raspistill. 4) the line command of the last photo (the pretty good one) was: "raspistill awb off awbg 0.88,0.58 -v -o test088058.jpg"
5) There is no zoom in the modulo cam :( so I can shoot just far from 1 meter to infininity because of the focus

have a look at the photo to see my camera

I could post other photos of plants in a little bit different custom white balance, if you think this will be usefull.

Thanks a lot for all DSCF3715.JPG

Reply to this comment...


Log in to comment