bugGNU Octave - Bugs: bug #50708, [octave forge] (image) add...


bug #50708: [octave forge] (image) add demosaic.m

Submitted by:  Timothy Parys <tparys>
Submitted on:  Sun 02 Apr 2017 10:46:52 PM UTC  
Category:  Octave Forge Package Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Patch Submitted Assigned to:  None
Originator Name:  Timothy Parys Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Tue 26 Sep 2017 01:21:27 PM UTC, comment #11: 

An alternative for the patent encumbered approach might be the one from which it is derived from, should still be better than bilinear:

S.-C. Pei and I.-K. Tam, “Effective color interpolation in CCD color filter arrays using signal correlation,” IEEE Trans. Circuits Systems Video Technol., vol. 13, no. 6, pp. 503-513, Jun. 2003.

Sat 24 Jun 2017 09:23:42 PM UTC, comment #10: 

Just curious, did this ever get added?
 I don't see it listed at https://sourceforge.net/p/octave/image/ci/default/tree/inst/ ?

Am I expected to do it? Not sure if I have commit access.

Wed 24 May 2017 06:29:54 PM UTC, comment #9: 

I recommend to insert this function to image package,
maybe with a "fixme" line about implementing another method(s).

Avinoam Kalma <avinoam>
Project Member
Tue 11 Apr 2017 01:58:56 AM UTC, comment #8: 

For the "if 1", that's something I saw on this page: https://www.gnu.org/software/octave/doc/interpreter/Demonstration-Functions.html

Re-reading that, it looks like that was only necessary if I were to define any functions in the demo. Since I'm not doing that, it probably doesn't belong. Also looks like I had some commented out references to subplots as well. Cleaned that out as well.

Also, just noticed the Octave convention of endif instead of end. That's an interesting difference I didn't notice until now. Thanks for the fix.

(file #40349)

Timothy Parys <tparys>
Mon 10 Apr 2017 06:18:06 AM UTC, comment #7: 


Thanks for the new submission, with the tests, and the nice demo.
I am uploading a new file, based on yours with

  • typos fixes
  • add sensorAlignment = tolower(sensorAlignment); so that "BGGR" can abe used.

Why did you use "if 1" in the demo?

If there no other comments, I recommend to add this function to image package. In the future we should implement another (un-patented) method, and let the user choose, like in
https://www.mathworks.com/help/vision/ref/demosaic.html in which the user can choose the Interpolation algorithm from "Bilinear" and "Gradient-corrected linear".

(file #40346)

Avinoam Kalma <avinoam>
Project Member
Sat 08 Apr 2017 12:15:17 AM UTC, comment #6: 

So, based on comments so far, I've left the interpolation algorithm as bilinear for now, and noted in the help text that it differs from the algorithm in use by Matlab.

I've drastically redone the code to remove the multiple of 2 restriction, and have done my best to adhere to the Octave coding style guide I found online.

There should be 11 tests and a demo implemented, if anyone's curious how their digital camera sees the world. The moire patterns in the second figure are actually pretty cool looking, though seems to  stress this related bug? http://savannah.gnu.org/bugs/?45372

Further feedback welcome.

(file #40327)

Timothy Parys <tparys>
Tue 04 Apr 2017 06:56:37 PM UTC, comment #5: 

I am no patent lawyer (but do have some experience in using patents). And to me this seems to be a valid US patent of the company Microsoft.  (A company that has money to pay lawyers...)

I will attach the (open source) original patend document as PDF. The second last page (with "claim 1") is the most important.

The patent was filed in March 2004, and is valid since 2009. The filing date is less than 20 years ago, so I would assume that the patent is still valid today. The quoted patend is valid in the US, but there are also other members of this patent family, for other countries today (namely China, Korea, Japan, Europe and World. The last two ones aren't exactly patents).

Matlab cites the following paper (from May 2004) in its help text of the demosaic command:

[1] Malvar, H.S., L. He, and R. Cutler, High quality linear interpolation for demosaicing of Bayer-patterned color images. ICASPP, Volume 34, Issue 11, pp. 2274-2282, May 2004.

So the patent submission was slightly earlier than this publication. This timing looks reasonable to me if someone really wants to hold a patent on this.

The fact that this is not patented in individual countries in Europe leads me to the sucpicion that this might not exactly be "worth" a patent. But currently some counties do have this method patented. Formally there are three ways of dealing with this:

  • pay money to Microsoft to purchase the right to use this patent
  • take Microsoft a US (and some asian) courts to fight this patent. And pay lawyers to do this fighting for you.
  • wait some (probably just 7) years, until the patent is not valid any more, at least the US patent.

The first two ways don't seem feasable to me for Octave code.

So what do we do about this? Should be just use the proposed code of Timothy, that might produce lesser quality results then the Matlab function? My vote would be: yes.

(file #40266)

Hartmut <hardy>
Mon 03 Apr 2017 10:36:30 PM UTC, comment #4: 

Malvar-He-Cutler appears patent encumbered?


Timothy Parys <tparys>
Mon 03 Apr 2017 08:12:57 PM UTC, comment #3: 

Thanks for contributing this function.

However, there are few problems:

This method uses a 5x5 filter (that's the reason for the minimal size)

  • There are no builtin self tests, as Carnë noted in comment #1.

Attached a new version which (try to) fix the first 6 items.

(file #40250)

Avinoam Kalma <avinoam>
Project Member
Mon 03 Apr 2017 05:46:35 PM UTC, comment #2: 

Shouldn't the function name not read "demosaic"? (letter a and i swapped)

Hartmut <hardy>
Mon 03 Apr 2017 12:45:07 PM UTC, comment #1: 

Hi! Thank you for the submission. Could you please provide some tests?

Carnë Draug <carandraug>
Project Member
Sun 02 Apr 2017 10:46:52 PM UTC, original submission:  

Found that octave did not have an implementation of demosiac. Wrote one while toying with Bayer images. Tested in Ubuntu 16.04.

Might also affect image-acquisition, per the comments in https://sourceforge.net/p/octave/image-acquisition/ci/ee385c9a7e1b7cf1897ca9ad9a53640de5f7ab70/tree/inst/SGRBGtoRGB.m

Timothy Parys <tparys>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #40349:  demosaic.m added by tparys (6KiB - text/x-objcsrc)
file #40346:  demosaic.m added by avinoam (6KiB - application/octet-stream)
file #40327:  demosaic.m added by tparys (6KiB - text/x-objcsrc)
file #40266:  US7502505B2.pdf added by hardy (2MiB - application/pdf)
file #40250:  demosaic.m added by avinoam (3KiB - application/octet-stream)
file #40238:  demosiac.m added by tparys (2KiB - text/x-objcsrc)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by avinoam (Updated the item)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by tparys (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-26 mtmiller Severity3 - Normal => 1 - Wish
        Priority5 - Normal => 3 - Low
        Release4.0.0 => dev
    2018-07-02 jwe Summary[octave-forge] (image) add demosaic.m => [octave forge] (image) add demosaic.m
    2017-08-11 jwe Summaryimage package: add demosaic.m => [octave-forge] (image) add demosaic.m
    2017-04-11 tparys Attached File- => Added demosaic.m, #40349
    2017-04-10 avinoam Attached File- => Added demosaic.m, #40346
    2017-04-08 tparys Attached File- => Added demosaic.m, #40327
    2017-04-04 hardy Attached File- => Added US7502505B2.pdf, #40266
    2017-04-03 avinoam Attached File- => Added demosaic.m, #40250
        Summaryimage package: add demosiac.m => image package: add demosaic.m
    2017-04-03 carandraug StatusNone => Patch Submitted
    2017-04-02 tparys Attached File- => Added demosiac.m, #40238

    Back to the top

    Powered by Savane 3.5