LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Bayer Filter and colour balance.

Hi all.

 

I have recently been acquiring images using a mikrotron MC1363 camera and LV code 'Grab and save to AVI'. I have then used ImageJ to create a stack of U8 images. My problem then arises in that I need to apply a bayer filter and colour balance to the images. I have been sent a correction matrix by mikrotron and extracted pixel intensities from the U8 images, but am now stuck. I don't know how to use the information accrued to give a debayered image of true colour. Any advice would be great.

 

Attached is:

 

Tthe MC1363 manual

The matrices supplied by mikrotron (lupa1300)

An image folder containing:

-A true colour image

-A snap taken using the MC1365 of the true colour image

-Images of the colours red, green, blue, white and black extracted from the bottom right hand image, as u8 jpegs.

 

 

Thanks.

 

Dan.

0 Kudos
Message 1 of 8
(4,177 Views)

Hi Danbubbles,

 

The pixels of the Bayer filter are arranged in a checkerboard pattern on the sensor. There are twice as many green as red and blue pixels in order to mimic the higher sensitivity of the human eye towards green light.

Due to the filter each pixel measures only one color. The two remaining colors are estimated (interpolated) using the eight surrounding pixels. This technique is called Bayer demosaicing or Bayer to RGB Conversion.

http://www.stemmer-imaging.co.uk/en/glossary/5287-Bayer-Filter

 

 

As far as I'm concerned there exit different "de-bayering" algorithm, which are different in terms of quality and performance, but in general

 

0#

you "move" a structuring element - which is like a subset of your input-image - across your input-picture starting at row = 0 column = 0, which is indexing the same pixel in both of your input AND output-image: http://www.mathworks.de/help/images/morph6.gif

 

1#

then you calculate a new value for this particular pixel in your output-image via interpolating the indexed pixel and its adjacent pixels in the input-image, e.g. like described in this pdf: 

http://www.matrix-vision.com/tl_files/mv11/Glossary/art_bayermosaic_en.pdf

 

2#

then you move on to the next pixel which should be at row 0, column 1

repeat, until you reach the pixel at row n, column m

 

 

 

 

 

 

 

 

Regards,
Alex

 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 2 of 8
(4,166 Views)

Hi Alex.

 

Thanks for the info. I have created a vi for extracting pixel intensities and understand how the algorithms work at the base level. My confusion comes with how to apply weightings from the matrix supplied, and also how the intensities are fed to the pixel in the output image. Is there a vi that contains an algorithm for applying a 3x3 operator at each pixel? If not, do you think splitting the image into 3 colour planes, recalculating intensities for each and combining will be the way to go?

 

Thanks.

 

Dan.

0 Kudos
Message 3 of 8
(4,144 Views)

Hi Dan,

 

unfortunately, I cann't open your attachment.

 

But here's my very basic - not optimised - approach to apply a 3x3 operator on an input image:

 

2013-06-25_structure-element.png

 

 

 

do you think splitting the image into 3 colour planes, recalculating intensities for each and combining will be the way to go

 

I'm not sure if I understand you right, but

 

a Pixel or Picture Element in a Labview Picture usually consists of 4 bytes (u32);

 

1. byte = red

2. byte = green

3. byte = blue

4. byte = not used

 

you might use http://zone.ni.com/reference/en-XX/help/371361F-01/lvpict/color_to_rgb/to split the color of your input pixel

 

and http://zone.ni.com/reference/en-XX/help/371361F-01/lvpict/rgb_to_color/ to join the r,g,b, empty - bytes together after interpolation

 

 

 

 

could you provide us with some sample images?

 

 

Regards,
Alex

0 Kudos
Message 4 of 8
(4,133 Views)

Hi Alex.

 

Attached I hope are a standard image containing target colours. Also is the image in its raw form from the camera and a matrix supplied without instruction by mikrotron to add weighting to the colour intensities.

0 Kudos
Message 5 of 8
(4,128 Views)

I can only assume, that the "least_squres_matrix.txt" reprents the 3x3 structurelement

 

but which value  corresponds to pixel 0|0 ? how have those factors to be ordered?

 

this could be one possible order:

 

1|-1          1|0            1|1

0.41683     0.60009     -0.06162


0|-1           0|0            0|1 
-0.01734     1.20559     -0.19259


-1|-1           -1|0            -1|1
-0.02780     -0.40563     1.26501

 

 

but, that's only one half of the story.

now you need to know what do do with those factors;

for example, you could be meant to multiplicate the subset's pixel with it's corresponding factor and sum those products to calculate the new pixel value in the output image.

But this is just a guess!

 

I recommend to ask your camera supplier about these issues

 

 

"colour calibration cropped.jpg" is the raw  input image and "colour imge,png.jpg" is the desired output image?

 

why do you want to use a .jpg for calibration?

due to a .jpg's lossy compression - wouldn't a .bmp or .png be better?

 

 

 

Regards,
Alex

 

 

0 Kudos
Message 6 of 8
(4,112 Views)

here's the result of my crude implementation of a 2x2 dither as described in http://www.matrix-vision.com/tl_files/mv11/Glossary/art_bayermosaic_en.pdf

 

this vi definetly needs some work, but I can't spend more time on this project

 

 

hop it's for some good ...

 

 

 

2013-06-26_raw to color.png

0 Kudos
Message 7 of 8
(4,084 Views)

Hi All

 

Rather than apply a bayer after image capture i've built in a bayer to the captue vi which is based on the example program 'Grab and save to AVI'. The RGB gains have been set using the White Balancing Utility provided by NI. Ideally i'd like to build in the WBU to my vi if it is possible so any advise would be good.

 

generate and apply bayer.png

0 Kudos
Message 8 of 8
(4,071 Views)