From 208936c5240be6419bb63e5735acae1ba797cb8e Mon Sep 17 00:00:00 2001
From: Carla Di Geronimo <carla.di-geronimo@grenoble-inp.org>
Date: Fri, 26 Jan 2024 15:57:08 +0100
Subject: [PATCH] Replace reconstruct.py

---
 src/methods/template/reconstruct.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/methods/template/reconstruct.py b/src/methods/template/reconstruct.py
index a97bd3f..7861be2 100755
--- a/src/methods/template/reconstruct.py
+++ b/src/methods/template/reconstruct.py
@@ -7,6 +7,7 @@ Students can call their functions (declared in others files of src/methods/your_
 import numpy as np
 
 from src.forward_model import CFA
+from src.methods.template.somefunc import spectral_difference, normalization, quad_bayer_to_bayer_pattern, quad_bayer_to_bayer_image, bilinear_interpolation
 
 
 def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray:
@@ -20,11 +21,26 @@ def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray:
         np.ndarray: Demosaicked image.
     """
     # Performing the reconstruction.
-    # TODO
+    
     input_shape = (y.shape[0], y.shape[1], 3)
     op = CFA(cfa, input_shape)
 
-    return np.zeros(op.input_shape)
+    if op.cfa != 'bayer' and op.cfa != 'quad_bayer':
+        raise ValueError("CFA must be bayer or quad_bayer")
+    
+    if op.cfa == 'quad_bayer':
+        quad_bayer_to_bayer_pattern(op)
+        quad_bayer_to_bayer_image(y)
+
+    # Apply adjoint operation on raw aquisition
+    z = op.adjoint(y)
+
+    # Demosaicing process
+    res_bi = bilinear_interpolation(op, z)
+    res_sd = spectral_difference(op, z, res_bi)
+    res = normalization(res_sd) # min-max normalization
+
+    return res
 
 
 ####
-- 
GitLab