Skip to content
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

PR: Switch extension mode in convolve to "mirror". #9

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions colour_demosaicing/bayer/demosaicing/bilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 3 additions & 3 deletions colour_demosaicing/bayer/demosaicing/malvar2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions colour_demosaicing/bayer/demosaicing/tests/test_bilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
16 changes: 16 additions & 0 deletions colour_demosaicing/bayer/demosaicing/tests/test_malvar2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
16 changes: 16 additions & 0 deletions colour_demosaicing/bayer/demosaicing/tests/test_menon2007.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -61,6 +62,21 @@ 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()