From 97fb470c627a12642e20fb56bdd39d09f8e04510 Mon Sep 17 00:00:00 2001 From: Matti Eskelinen Date: Tue, 18 Sep 2018 14:33:23 +0300 Subject: [PATCH 1/3] Switch extension mode in convolve to 'mirror' --- colour_demosaicing/bayer/demosaicing/bilinear.py | 6 +++--- colour_demosaicing/bayer/demosaicing/malvar2004.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/colour_demosaicing/bayer/demosaicing/bilinear.py b/colour_demosaicing/bayer/demosaicing/bilinear.py index ad0a546..92a8301 100644 --- a/colour_demosaicing/bayer/demosaicing/bilinear.py +++ b/colour_demosaicing/bayer/demosaicing/bilinear.py @@ -105,8 +105,8 @@ def demosaicing_CFA_Bayer_bilinear(CFA, pattern='RGGB'): [2, 4, 2], [1, 2, 1]]) / 4 # yapf: disable - R = convolve(CFA * R_m, H_RB) - G = convolve(CFA * G_m, H_G) - B = convolve(CFA * B_m, H_RB) + R = convolve(CFA * R_m, H_RB, mode='mirror') + G = convolve(CFA * G_m, H_G, mode='mirror') + B = convolve(CFA * B_m, H_RB, mode='mirror') return tstack((R, G, B)) diff --git a/colour_demosaicing/bayer/demosaicing/malvar2004.py b/colour_demosaicing/bayer/demosaicing/malvar2004.py index ba300f6..9b8d42c 100644 --- a/colour_demosaicing/bayer/demosaicing/malvar2004.py +++ b/colour_demosaicing/bayer/demosaicing/malvar2004.py @@ -127,9 +127,9 @@ def demosaicing_CFA_Bayer_Malvar2004(CFA, pattern='RGGB'): G = np.where(np.logical_or(R_m == 1, B_m == 1), convolve(CFA, GR_GB), G) - RBg_RBBR = convolve(CFA, Rg_RB_Bg_BR) - RBg_BRRB = convolve(CFA, Rg_BR_Bg_RB) - RBgr_BBRR = convolve(CFA, Rb_BB_Br_RR) + RBg_RBBR = convolve(CFA, Rg_RB_Bg_BR, mode='mirror') + RBg_BRRB = convolve(CFA, Rg_BR_Bg_RB, mode='mirror') + RBgr_BBRR = convolve(CFA, Rb_BB_Br_RR, mode='mirror') # Red rows. R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * np.ones(R.shape) From 4fb0c288e14fd2a56a1a82d22dfa04c6270e3b90 Mon Sep 17 00:00:00 2001 From: Matti Eskelinen Date: Tue, 18 Sep 2018 17:36:33 +0300 Subject: [PATCH 2/3] Add tests to check that the methods result in interpolants --- .../bayer/demosaicing/tests/test_bilinear.py | 16 ++++++++++++++++ .../bayer/demosaicing/tests/test_malvar2004.py | 16 ++++++++++++++++ .../bayer/demosaicing/tests/test_menon2007.py | 17 +++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py b/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py index 90fb294..8049a82 100644 --- a/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py +++ b/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py @@ -15,6 +15,7 @@ from colour_demosaicing import TESTS_RESOURCES_DIRECTORY from colour_demosaicing.bayer import demosaicing_CFA_Bayer_bilinear +from colour.demosaicing.bayer import mosaicing_CFA_Bayer __author__ = 'Colour Developers' __copyright__ = 'Copyright (C) 2015-2018 - Colour Developers' @@ -51,6 +52,21 @@ def test_demosaicing_CFA_Bayer_bilinear(self): read_image(str(RGB.format(pattern))), decimal=7) + def test_demosaicing_CFA_Bayer_bilinear_interpolant(self): + """ + Tests whether the result of :func:`colour_demosaicing.bayer.\ + demosaicing.bilinear.demosaicing_CFA_Bayer_bilinear` agrees + with the original values. + """ + + for pattern in ('RGGB', 'BGGR', 'GRGB', 'GBRG'): + CFA_file = os.path.join(BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr') + + CFA = read_image(str(CFA_file.format(pattern))) + RGB = demosaicing_CFA_Bayer_bilinear(CFA, pattern) + CFA_from_RGB = mosaicing_CFA_Bayer(RGB, pattern) + np.testing.assert_almost_equal(CFA_from_RGB, CFA, decimal=7) + if __name__ == '__main__': unittest.main() diff --git a/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py b/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py index 93c7570..9c0e89b 100644 --- a/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py +++ b/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py @@ -15,6 +15,7 @@ from colour_demosaicing import TESTS_RESOURCES_DIRECTORY from colour_demosaicing.bayer import demosaicing_CFA_Bayer_Malvar2004 +from colour.demosaicing.bayer import mosaicing_CFA_Bayer __author__ = 'Colour Developers' __copyright__ = 'Copyright (C) 2015-2018 - Colour Developers' @@ -52,6 +53,21 @@ def test_demosaicing_CFA_Bayer_Malvar2004(self): read_image(str(RGB.format(pattern))), decimal=7) + def test_demosaicing_CFA_Bayer_Malvar2004_interpolant(self): + """ + Tests whether the result of :func:`colour_demosaicing.bayer.\ + demosaicing.bilinear.demosaicing_CFA_Bayer_Malvar2004` agrees + with the original values. + """ + + for pattern in ('RGGB', 'BGGR', 'GRGB', 'GBRG'): + CFA_file = os.path.join(BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr') + + CFA = read_image(str(CFA_file.format(pattern))) + RGB = demosaicing_CFA_Bayer_Malvar2004(CFA, pattern) + CFA_from_RGB = mosaicing_CFA_Bayer(RGB, pattern) + np.testing.assert_almost_equal(CFA_from_RGB, CFA, decimal=7) + if __name__ == '__main__': unittest.main() diff --git a/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py b/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py index a5ea761..5042cf0 100644 --- a/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py +++ b/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py @@ -15,6 +15,7 @@ from colour_demosaicing import TESTS_RESOURCES_DIRECTORY from colour_demosaicing.bayer import demosaicing_CFA_Bayer_Menon2007 +from colour.demosaicing.bayer import mosaicing_CFA_Bayer __author__ = 'Colour Developers' __copyright__ = 'Copyright (C) 2015-2018 - Colour Developers' @@ -61,6 +62,22 @@ def test_demosaicing_CFA_Bayer_Menon2007(self): read_image(str(RGB.format(pattern))), decimal=7) + def test_demosaicing_CFA_Bayer_Menon2007_interpolant(self): + """ + Tests whether the result of :func:`colour_demosaicing.bayer.\ + demosaicing.bilinear.demosaicing_CFA_Bayer_Menon2007` agrees + with the original values. + """ + + for pattern in ('RGGB', 'BGGR', 'GRGB', 'GBRG'): + CFA_file = os.path.join(BAYER_DIRECTORY, 'Lighthouse_CFA_{0}.exr') + + CFA = read_image(str(CFA_file.format(pattern))) + RGB = demosaicing_CFA_Bayer_Menon2007(CFA, pattern) + CFA_from_RGB = mosaicing_CFA_Bayer(RGB, pattern) + np.testing.assert_almost_equal(CFA_from_RGB, CFA, decimal=7) + + if __name__ == '__main__': unittest.main() From 5470a538323adfc14779e4444e36c3af69945dd7 Mon Sep 17 00:00:00 2001 From: Matti Eskelinen Date: Wed, 19 Sep 2018 16:23:42 +0300 Subject: [PATCH 3/3] Fix typo --- colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py | 2 +- colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py | 2 +- colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py b/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py index 8049a82..d248403 100644 --- a/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py +++ b/colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py @@ -15,7 +15,7 @@ from colour_demosaicing import TESTS_RESOURCES_DIRECTORY from colour_demosaicing.bayer import demosaicing_CFA_Bayer_bilinear -from colour.demosaicing.bayer import mosaicing_CFA_Bayer +from colour_demosaicing.bayer import mosaicing_CFA_Bayer __author__ = 'Colour Developers' __copyright__ = 'Copyright (C) 2015-2018 - Colour Developers' diff --git a/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py b/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py index 9c0e89b..7bcabd2 100644 --- a/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py +++ b/colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py @@ -15,7 +15,7 @@ from colour_demosaicing import TESTS_RESOURCES_DIRECTORY from colour_demosaicing.bayer import demosaicing_CFA_Bayer_Malvar2004 -from colour.demosaicing.bayer import mosaicing_CFA_Bayer +from colour_demosaicing.bayer import mosaicing_CFA_Bayer __author__ = 'Colour Developers' __copyright__ = 'Copyright (C) 2015-2018 - Colour Developers' diff --git a/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py b/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py index 5042cf0..35eaa91 100644 --- a/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py +++ b/colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py @@ -15,7 +15,7 @@ from colour_demosaicing import TESTS_RESOURCES_DIRECTORY from colour_demosaicing.bayer import demosaicing_CFA_Bayer_Menon2007 -from colour.demosaicing.bayer import mosaicing_CFA_Bayer +from colour_demosaicing.bayer import mosaicing_CFA_Bayer __author__ = 'Colour Developers' __copyright__ = 'Copyright (C) 2015-2018 - Colour Developers' @@ -78,6 +78,5 @@ def test_demosaicing_CFA_Bayer_Menon2007_interpolant(self): np.testing.assert_almost_equal(CFA_from_RGB, CFA, decimal=7) - if __name__ == '__main__': unittest.main()