Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 29th November 2007, 01:36   #1  |  Link
Ignus2
Registered User
 
Join Date: Dec 2005
Posts: 250
demosaic/debayer

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.
Attached Images
 
Ignus2 is offline   Reply With Quote
Old 29th November 2007, 10:30   #2  |  Link
bill_baroud
Registered User
 
Join Date: Feb 2002
Posts: 407
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...
bill_baroud is offline   Reply With Quote
Old 29th November 2007, 20:15   #3  |  Link
Ignus2
Registered User
 
Join Date: Dec 2005
Posts: 250
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.
Ignus2 is offline   Reply With Quote
Old 29th November 2007, 20:39   #4  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
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.
__________________
Regards, sh0dan // VoxPod
sh0dan is offline   Reply With Quote
Old 30th November 2007, 10:40   #5  |  Link
bill_baroud
Registered User
 
Join Date: Feb 2002
Posts: 407
Quote:
Originally Posted by Ignus2 View Post
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

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

Last edited by bill_baroud; 30th November 2007 at 10:44.
bill_baroud is offline   Reply With Quote
Old 1st December 2007, 04:49   #6  |  Link
Ignus2
Registered User
 
Join Date: Dec 2005
Posts: 250
@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.

Quote:
Originally Posted by bill_baroud View Post
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.
Ignus2 is offline   Reply With Quote
Old 1st December 2007, 09:21   #7  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
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.
foxyshadis is offline   Reply With Quote
Old 3rd December 2007, 11:02   #8  |  Link
bill_baroud
Registered User
 
Join Date: Feb 2002
Posts: 407
Quote:
Originally Posted by Ignus2 View Post
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 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...


Quote:
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

Quote:
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
bill_baroud is offline   Reply With Quote
Old 4th December 2007, 09:35   #9  |  Link
sh0dan
Retired AviSynth Dev ;)
 
sh0dan's Avatar
 
Join Date: Nov 2001
Location: Dark Side of the Moon
Posts: 3,480
@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."
__________________
Regards, sh0dan // VoxPod

Last edited by sh0dan; 4th December 2007 at 09:39.
sh0dan is offline   Reply With Quote
Old 6th December 2007, 04:15   #10  |  Link
Ignus2
Registered User
 
Join Date: Dec 2005
Posts: 250
Quote:
Originally Posted by sh0dan View Post
@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.

Last edited by Ignus2; 4th March 2008 at 00:01.
Ignus2 is offline   Reply With Quote
Old 6th December 2007, 14:41   #11  |  Link
pandy
Registered User
 
Join Date: Mar 2006
Posts: 1,049
Quote:
Originally Posted by sh0dan View Post
@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
pandy is offline   Reply With Quote
Old 4th March 2008, 00:04   #12  |  Link
Ignus2
Registered User
 
Join Date: Dec 2005
Posts: 250
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.
Attached Files
File Type: zip demosaic.zip (164.1 KB, 461 views)

Last edited by Ignus2; 25th June 2008 at 19:44.
Ignus2 is offline   Reply With Quote
Old 18th April 2013, 13:51   #13  |  Link
Terka
Registered User
 
Join Date: Jan 2005
Location: cz
Posts: 704
Cant load the plugin.
Error: "Not an Avisynth 2 C plugin"
Could anyone help?
Terka is offline   Reply With Quote
Old 18th April 2013, 21:58   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Terka,
http://www.mediafire.com/?1m27l83h1uvl1uj

Converted to CPP plugin, not much testing done.

Contains source + original source.

EDIT: Name is DemosaicCPP.dll, same args as original.

Code:
// Plugin parameters:
// ------------------
// DemosaicCPP(clip, string mosaic, string method, int xoffset, int yoffset)
//
// clip    clip: input clip, can be YUY2, YV12 or Y8
// string  mosaic (default: "Bayer"): the color filter array arrangement. Currently only "Bayer" is supported.
// string  method (default: "bilinear"): interpolation method: "bilinear" or "nearest"
// int     xoffset (default: 0): color filter array x offset value.
// int     yoffset (default: 0): color filter array y offset value.
// 
// output: RGB32 color image
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 18th April 2013 at 22:29.
StainlessS is offline   Reply With Quote
Old 19th April 2013, 12:14   #15  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Terka View Post
Cant load the plugin.
Error: "Not an Avisynth 2 C plugin"
StainlessS's rewritten version might be a solution, but the original works fine for me (using the latest version from post #12).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 19th April 2013, 17:59   #16  |  Link
Terka
Registered User
 
Join Date: Jan 2005
Location: cz
Posts: 704
Thanks a lot, ill try.
Want to try denoise before debayer for really high iso settings.
Is there some median or weighted median filter that uses only some pixels?
abc
def
ghi

for example only replace the e with a,c,g,i or even bigger radius.
maybe ill put some samples.
If anyone played with something similar, please post your comments.
post 12 link did not work for me
Terka is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:19.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.