View Full Version : demosaic/debayer
Ignus2
29th November 2007, 01:36
Hi!
We acquired a new camera for our school project, and it outputs something called bayer pattern image. It is me very first time learning about this kind of stuff, I never knew most digital cameras and the like use this.
Anyhow, I need a debayering filter, and I'm asking if anyone has written one so far (for either avisynth or dshow). I saw some posts on the forums mentioning debayering, but no plugin.
I tried writing one myself, quite primitive. A first try image is attached. Anyone able to help me with this?
--
Greets,
I.
bill_baroud
29th November 2007, 10:30
Yes I have : http://forum.doom9.org/showthread.php?t=127829 (did you use search :whistle: ?)
I didn't publish it because it's still quite rough, not very fast (12 fps @ 1080p on my 1.86ghz c2d laptop) not very tested and i don't know about quality.
And i don't know anything about the intellectual property involved, so i should try to contact the authors of the paper...
Ignus2
29th November 2007, 20:15
Hmmm..., I see. Though that thread's subject isn't too descriptive :)
Anyhow, we need a throughput of around 200 fps preferably on a lower quality mode (for preview), but high quality modes are better of course for later processing.
Actually, supporting Y8 is not a problem, because only the input is affected, and in that case Avisynth 2.5 will never give you Y8, so the same code can be used for both 2.5/2.6.
I can attach the code if you wish. It's really darn primitive, I haven't read any paper about this yet :)
What I'm concerned about is white balance and color correction. I've read, that these also must be taken into account. I don't know anything about these things yet.
I welcome any good ideas/pointers in this matter.
--
Greets,
I.
sh0dan
29th November 2007, 20:39
A good demosaic is quite a hard task. You can have a look at dcraw, which implements Variable Number of Gradients and Pixel Grouping.
http://cybercom.net/~dcoffin/dcraw/
http://web.cecs.pdx.edu/~cklin/demosaic/
You need a gamma correction of 2.2 for linear to sRBG conversion. The color correction is dependent on the individual hardware, so I cannot help you there.
bill_baroud
30th November 2007, 10:40
Hmmm..., I see. Though that thread's subject isn't too descriptive :)
Anyhow, we need a throughput of around 200 fps preferably on a lower quality mode (for preview), but high quality modes are better of course for later processing.
200fps, but for what kind of resolution ? Anyway at that speed, you're going to be limited to simple bilinear or something interpolation, and probably a SIMD one ;) ...
If you really want to test it, i can provide a binary of my filter but can't be held responsible if it blows your computer :D
edit : as for color problem, i just have no clue about that aspect of the problem. My filter was merely a test to see if i was able to translate maths from a paper to code. I will gladly follow your investigation on that matter ;)
Ignus2
1st December 2007, 04:49
@sh0dan
Thanks sh0dan. I already took a look at dcraw. The whole program is a single huge C file. Quite hard to decode :)
I'll see what I can do with it.
200fps, but for what kind of resolution ?
Full. :)
The image you see above is the resolution of the camera (656*493 to be precise).
I'll accept any kind of code as long as it's not a format c: or something similar :)
What are your sources BTW for testing the algorithm? Do you have access to a camera, that provides raw bayer-pattern images?
--
Greets,
I.
foxyshadis
1st December 2007, 09:21
GreyCStoration is reasonably good and reasonably fast, though you'd need a monster machine to make it that fast. Scripts I usually use are closer to spf than fps (but I also use it on multi-megapixel snaps), so I can't really help.
bill_baroud
3rd December 2007, 11:02
I already took a look at dcraw. The whole program is a single huge C file. Quite hard to decode :)
You said it, it's unreadable :scared: I banged my head numerous time on my desk before understanding part of the code, and it's still quite obscure for me. It's my Worse Code Ever award...
Full. :)
The image you see above is the resolution of the camera (656*493 to be precise).
I'll accept any kind of code as long as it's not a format c: or something similar :)
Full doesn't mean anything ;)
Anyway you can try : http://moodub.free.fr/video/Avisynth_DebayerFilter.zip
No docs, no waranty :sly:
What are your sources BTW for testing the algorithm? Do you have access to a camera, that provides raw bayer-pattern images?
I've some raw (HD) files that comes straight from a sensor.
I've also a camera but i'm still messing around with verilog and the fpga to get the raw pictures ;)
sh0dan
4th December 2007, 09:35
@Ignus2: Could you post some material we could test on, and perhaps the source code of your current plugin?
Yes dcraw is probably the worst code I've seen to date. To quote David Coffin: "[I] Firmly believe that programming is an art, not a science, and that beautiful code is more reliable and easier to maintain." :)
Ignus2
6th December 2007, 04:15
@Ignus2: Could you post some material we could test on, and perhaps the source code of your current plugin?
Well, I'll try to get something, but that'll probably only be pics, as the video files tend to get huge. We're using 4 disks 500 GB each in RAID 0, so we can write the video fast enough. 10 seconds of video is around 700 MB (uncompressed 8 bit).
@bill:
I've tried your plugin, it looks OK, though indeed quite CPU intensive. Can you post source?
In the meantime, here's mine. It could hardly be any more primitive, but oh well. Source included.
EDIT: Look below for updated plugin.
--
Greets,
I.
pandy
6th December 2007, 14:41
@Ignus2: Could you post some material we could test on, and perhaps the source code of your current plugin?
i think that probably the better idea is to create some kind "re-bayer" filter - maybe for various patterns which are used in optic sensors
Ignus2
4th March 2008, 00:04
I made some updates to the plugin, added "bilinear" interpolation or whatever, I don't even know if that's what it's called or just something similar.
It is possible now to offset the bayer pattern, though it will result in black borders.
The archive also includes a test image and test script.
Oh, and I found out that white balance can be done with RGBAdjust() :)
EDIT: If anyone's interested in the algorithm, here's the link I read: http://www.siliconimaging.com/RGB Bayer.htm
--
Greets,
I.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.