diff --git a/src/methods/Samia_Bouddahab/Project_Image_Analysis.pdf b/src/methods/Samia_Bouddahab/Project_Image_Analysis.pdf new file mode 100644 index 0000000000000000000000000000000000000000..00bf69cbe7d96fe7d51e9a86b1fc2af1db6d5e8f Binary files /dev/null and b/src/methods/Samia_Bouddahab/Project_Image_Analysis.pdf differ diff --git a/src/methods/Samia_Bouddahab/function.py b/src/methods/Samia_Bouddahab/function.py new file mode 100644 index 0000000000000000000000000000000000000000..794193a7eb8b89d21b77f7335a2131d525ae6d2e --- /dev/null +++ b/src/methods/Samia_Bouddahab/function.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Feb 12 07:38:51 2024 + +@author: etudiant +""" +import numpy as np +from scipy.signal import convolve2d +from src.forward_model import CFA +from scipy.ndimage import convolve + + +def malvar_demosaicing(op: CFA, y: np.ndarray) -> np.ndarray: + """ + Performs a malvar interpolation. + + Args: + op (CFA): CFA operator. + y (np.ndarray): Mosaicked image. + + Returns: + np.ndarray: Demosaicked image. + """ + z = op.adjoint(y) + # Definnig Masks + R_m = op.mask[:, :, 0] + G_m = op.mask[:, :, 1] + B_m = op.mask[:, :, 2] + + GR_GB = np.array([ + [0.0, 0.0, -1.0, 0.0, 0.0], + [0.0, 0.0, 2.0, 0.0, 0.0], + [-1.0, 2.0, 4.0, 2.0, -1.0], + [0.0, 0.0, 2.0, 0.0, 0.0], + [0.0, 0.0, -1.0, 0.0, 0.0], + ]) / 8 + + Rg_RB_Bg_BR = np.array( + [ + [0.0, 0.0, 0.5, 0.0, 0.0], + [0.0, -1.0, 0.0, -1.0, 0.0], + [-1.0, 4.0, 5.0, 4.0, -1.0], + [0.0, -1.0, 0.0, -1.0, 0.0], + [0.0, 0.0, 0.5, 0.0, 0.0], + ]) / 8 + + Rg_BR_Bg_RB = np.transpose(Rg_RB_Bg_BR) + + Rb_BB_Br_RR = np.array( + [ + [0.0, 0.0, -1.5, 0.0, 0.0], + [0.0, 2.0, 0.0, 2.0, 0.0], + [-1.5, 0.0, 6.0, 0.0, -1.5], + [0.0, 2.0, 0.0, 2.0, 0.0], + [0.0, 0.0, -1.5, 0.0, 0.0], + ]) / 8 + + R = y * R_m + G = y * G_m + B = y * B_m + + del G_m + + G = np.where(np.logical_or(R_m == 1, B_m == 1), convolve(y, GR_GB), G) + + RBg_RBBR = convolve(y, Rg_RB_Bg_BR) + RBg_BRRB = convolve(y, Rg_BR_Bg_RB) + RBgr_BBRR = convolve(y, Rb_BB_Br_RR) + + 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)[None]) * np.ones(R.shape) + # Red columns. + R_c = np.any(R_m == 1, axis=0)[None] * np.ones(R.shape) + # Blue rows. + B_r = np.transpose(np.any(B_m == 1, axis=1)[None]) * np.ones(B.shape) + # Blue columns + B_c = np.any(B_m == 1, axis=0)[None] * np.ones(B.shape) + + del R_m, B_m + + R = np.where(np.logical_and(R_r == 1, B_c == 1), RBg_RBBR, R) + R = np.where(np.logical_and(B_r == 1, R_c == 1), RBg_BRRB, R) + + B = np.where(np.logical_and(B_r == 1, R_c == 1), RBg_RBBR, B) + B = np.where(np.logical_and(R_r == 1, B_c == 1), RBg_BRRB, B) + + R = np.where(np.logical_and(B_r == 1, B_c == 1), RBgr_BBRR, R) + B = np.where(np.logical_and(R_r == 1, R_c == 1), RBgr_BBRR, B) + + del RBg_RBBR, RBg_BRRB, RBgr_BBRR, R_r, R_c, B_r, B_c + # Combine channels + return np.clip(np.stack((R, G, B), axis=-1), 0, 1) diff --git a/src/methods/Samia_Bouddahab/reconstruct.py b/src/methods/Samia_Bouddahab/reconstruct.py new file mode 100644 index 0000000000000000000000000000000000000000..92307a6185cfa95312777e4f3319fe4a949caba5 --- /dev/null +++ b/src/methods/Samia_Bouddahab/reconstruct.py @@ -0,0 +1,53 @@ +"""The main file for the reconstruction. +This file should NOT be modified except the body of the 'run_reconstruction' function. +Students can call their functions (declared in others files of src/methods/your_name). +""" + + +import numpy as np + +from src.forward_model import CFA + + +def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray: + """Performs demosaicking on y. + + Args: + y (np.ndarray): Mosaicked image to be reconstructed. + cfa (str): Name of the CFA. Can be bayer or quad_bayer. + + Returns: + np.ndarray: Demosaicked image. + """ + # Performing the reconstruction. + # TODO + input_shape = (y.shape[0], y.shape[1], 3) + op = CFA(cfa, input_shape) + res = malvar_demosaicing(op, y) + return np.zeros(op.input_shape) + + +#### +#### +#### + +#### #### #### ############# +#### ###### #### ################## +#### ######## #### #################### +#### ########## #### #### ######## +#### ############ #### #### #### +#### #### ######## #### #### #### +#### #### ######## #### #### #### +#### #### ######## #### #### #### +#### #### ## ###### #### #### ###### +#### #### #### ## #### #### ############ +#### #### ###### #### #### ########## +#### #### ########## #### #### ######## +#### #### ######## #### #### +#### #### ############ #### +#### #### ########## #### +#### #### ######## #### +#### #### ###### #### + +# 2023 +# Authors: Mauro Dalla Mura and Matthieu Muller