Skip to content

Commit

Permalink
Use "colour" array constructors to give a chance to reduce memory usa…
Browse files Browse the repository at this point in the history
…ge through bit-depth change.

References #42.
  • Loading branch information
KelSolaar committed Apr 7, 2022
1 parent 5cc1293 commit bd97285
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 5 additions & 5 deletions colour_demosaicing/bayer/demosaicing/malvar2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from scipy.ndimage.filters import convolve

from colour.hints import ArrayLike, Literal, NDArray, Union
from colour.utilities import as_float_array, tstack
from colour.utilities import as_float_array, ones, tstack

from colour_demosaicing.bayer import masks_CFA_Bayer

Expand Down Expand Up @@ -157,13 +157,13 @@ def demosaicing_CFA_Bayer_Malvar2004(
del GR_GB, Rg_RB_Bg_BR, Rg_BR_Bg_RB, Rb_BB_Br_RR

# Red rows.
R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * np.ones(R.shape)
R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * ones(R.shape)
# Red columns.
R_c = np.any(R_m == 1, axis=0)[np.newaxis] * np.ones(R.shape)
R_c = np.any(R_m == 1, axis=0)[np.newaxis] * ones(R.shape)
# Blue rows.
B_r = np.transpose(np.any(B_m == 1, axis=1)[np.newaxis]) * np.ones(B.shape)
B_r = np.transpose(np.any(B_m == 1, axis=1)[np.newaxis]) * ones(B.shape)
# Blue columns
B_c = np.any(B_m == 1, axis=0)[np.newaxis] * np.ones(B.shape)
B_c = np.any(B_m == 1, axis=0)[np.newaxis] * ones(B.shape)

del R_m, B_m

Expand Down
16 changes: 8 additions & 8 deletions colour_demosaicing/bayer/demosaicing/menon2007.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from scipy.ndimage.filters import convolve, convolve1d

from colour.hints import ArrayLike, Boolean, Literal, NDArray, Union
from colour.utilities import as_float_array, tsplit, tstack
from colour.utilities import as_float_array, ones, tsplit, tstack

from colour_demosaicing.bayer import masks_CFA_Bayer

Expand Down Expand Up @@ -160,9 +160,9 @@ def demosaicing_CFA_Bayer_Menon2007(
del d_H, d_V, G_H, G_V

# Red rows.
R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * np.ones(R.shape)
R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * ones(R.shape)
# Blue rows.
B_r = np.transpose(np.any(B_m == 1, axis=1)[np.newaxis]) * np.ones(B.shape)
B_r = np.transpose(np.any(B_m == 1, axis=1)[np.newaxis]) * ones(B.shape)

k_b = as_float_array([0.5, 0, 0.5])

Expand Down Expand Up @@ -290,7 +290,7 @@ def refining_step_Menon2007(
R_G = R - G
B_G = B - G

FIR = np.ones(3) / 3
FIR = ones(3) / 3

B_G_m = np.where(
B_m == 1,
Expand All @@ -310,13 +310,13 @@ def refining_step_Menon2007(

# Updating of the red and blue components in the green locations.
# Red rows.
R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * np.ones(R.shape)
R_r = np.transpose(np.any(R_m == 1, axis=1)[np.newaxis]) * ones(R.shape)
# Red columns.
R_c = np.any(R_m == 1, axis=0)[np.newaxis] * np.ones(R.shape)
R_c = np.any(R_m == 1, axis=0)[np.newaxis] * ones(R.shape)
# Blue rows.
B_r = np.transpose(np.any(B_m == 1, axis=1)[np.newaxis]) * np.ones(B.shape)
B_r = np.transpose(np.any(B_m == 1, axis=1)[np.newaxis]) * ones(B.shape)
# Blue columns.
B_c = np.any(B_m == 1, axis=0)[np.newaxis] * np.ones(B.shape)
B_c = np.any(B_m == 1, axis=0)[np.newaxis] * ones(B.shape)

R_G = R - G
B_G = B - G
Expand Down
6 changes: 2 additions & 4 deletions colour_demosaicing/bayer/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

from __future__ import annotations

import numpy as np

from colour.hints import Literal, NDArray, Tuple, Union
from colour.utilities import validate_method
from colour.utilities import validate_method, zeros

__author__ = "Colour Developers"
__copyright__ = "Copyright 2015 Colour Developers"
Expand Down Expand Up @@ -75,7 +73,7 @@ def masks_CFA_Bayer(
'"{0}" CFA pattern is invalid, it must be one of {1}!',
).upper()

channels = {channel: np.zeros(shape) for channel in "RGB"}
channels = {channel: zeros(shape) for channel in "RGB"}
for channel, (y, x) in zip(pattern, [(0, 0), (0, 1), (1, 0), (1, 1)]):
channels[channel][y::2, x::2] = 1

Expand Down

0 comments on commit bd97285

Please sign in to comment.