-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageBufferAlgo::demosaic (IBA::demosaic) #4364
Comments
There isn't really an "OpenCV plugin", just really simple functions to convert between a cv::Mat and an ImageBuf. (In fact, #4363 even makes them just inline function utilities, eliminating OpenCV as a direct dependency of libOpenImageIO). If libraw (a) exposes the demosaicing from/to a buffer separately from their reading whole raw files, so we can call that directly, and (b) we trust their implementation and don't want to do anything different, and (c) we're ok with IBA::demosaic() only working if the optional libraw dependency is found at build time, then we could implement IBA::demosic as basically a wrapper around the libraw functionality. But if you think that it's better for us to control our own fate, so to speak, then maybe we just want a completely new, full implementation of demosaicing in IBA::demosaic without any reliance on libraw. |
For integer pixels, that's probably a wise choice. But they do not support floats. |
Based on what you wrote above, it also looks like the libraw entry point wants the data encoded in a very specific way, which is probably related to the libraw decoding internals and does not resemble how data will be laid out in an ImageBuf. Therefore, trying to use that libraw function to and from IB will involve extra data translations in and out, which is really going to hurt performance and seems silly. It's probably better to write an IB-to-IB demosaicing function from scratch. |
I've implemented a simple linear demosaicing, just to learn how to write an IBA. @ssh4net the code is functional, I've tested it on a bunch of images, in case you wanted to give it a go. There is still room for optimisation, but that is not a priority at this stage. @lgritz, I've got a few questions I'd like answered before continuing the work on the actual algos:
I've also put a simple test into imagebufalgo_test which converts a bunch of raw images with hardcoded filenames. That is for debugging, I will make a proper test with generated images later. |
Wow! So fast! I also thought to use own cpp file for demosaics code. As soon as we will definitely implement more than one interpolation algorithm, that might be worth on start implement some switch for using algo. Maybe similar to IBA::blur, just made a single entry "linear". As for single channel vs RGB. When I thought to implement demosaic I hold in mind only single channel images. But your question remind me another use case. Usually raw data is single channel. But people can decode raw sensor data using libraw/dcraw to RGB mosaiced images. And that representation can be more common for people not deeply in topic. Regarding bit depth. |
I've refactored the code a bit. There is now a base class BayerDemosaicing and 2 subclasses LinearBayerDemosaicing and MHCBayerDemosaicing. The latter implements the Malvar-He-Cutler algorithm (https://www.ipol.im/pub/art/2011/g_mhcd/article.pdf). It is just slightly slower than the simple linear one, but gives significantly better results. I am actually not convinced that we should vendor multiple demosaicing methods. I would rather have a single robust algo for each sensor type. Should we want to expose the base class in the public interfaces, it would be pretty easy for the users to implement additional algos on their side. All they'd need to do is to specify the kernel size as a template param and override 4 methods implementing convolution for the 4 photosite types. |
Great!! I thought about AHD (ADAPTIVE HOMOGENEITY-DIRECTED DEMOSAICING ALGORITHM) which is a default libraw algorithm and the one had a good balance in quality and speed. I think a single function ImageBufAlgo::bayer_demosaic() with string_view method similar to IBA::unsharp_mask is more convenient than use per algorythm public function.
Or you think that some algo might require additional parameters? |
OpenImageIO already supports different demosaic algorithms via the libraw or OpenCV plugin.
Technically, as soon as libraw is already built and the library is present, it is possible to call libraw to demosaic routine passing binary blob to it. That should work fine for 8/12/16-bit inputs. In most cases, users are OK with that.
But if you need demosaic float imagery there are only OpenCV can help. The problem is that OpenCV as a meta library is probably even bigger than OIIO. And building OIIO with OpenCV only for demosaic is probably a huge overhead.
So, the idea is to implement a lightweight Demosaic function as a part of ImageBufferAlgo with the support of all bit depths OIIO.
For start it can be a simple Linear Demosaic. Later it can be extended by adding other open source algorithms.
The text was updated successfully, but these errors were encountered: