Skip to content
Snippets Groups Projects
Commit ce110448 authored by Matthieu Muller's avatar Matthieu Muller
Browse files

Merge branch 'master' into 'master'

charpela

See merge request !40
parents 221b1656 bd883f3f
No related branches found
No related tags found
1 merge request!40charpela
File added
import numpy as np
import cv2
from scipy.signal import convolve2d
from src.forward_model import CFA
def superpixel(op: CFA, y: np.ndarray) -> np.ndarray:
"""Performs the method of variable number of gradients
Args:
op (CFA): CFA operator.
y (np.ndarray): Mosaicked image.
Returns:
np.ndarray: Demosaicked image.
"""
z = op.adjoint(y)
if op.cfa == 'bayer':
res = np.empty((op.input_shape[0]//2, op.input_shape[1]//2, op.input_shape[2]))
for i in range(1,op.input_shape[0],2):
for j in range(1, op.input_shape[1],2):
res[i//2,j//2,0] = z[ i-1,j ,0]
res[i//2,j//2,1] = (z[i,j,1] + z[i-1,j-1,1]) / 2
res[i//2,j//2,2] = z[ i,j-1 ,2]
else:
res = np.empty((op.input_shape[0]//2, op.input_shape[1]//2, op.input_shape[2]))
print()
for i in range(2,op.input_shape[0]-5,4):
for j in range(2, op.input_shape[1]-5,4):
res[i//2,j//2,0] = z[ i-2,j ,0]
res[i//2,j//2,1] = (z[i,j,1] + z[i-2,j-2,1]) / 2
res[i//2,j//2,2] = z[ i,j-2 ,2]
res[i//2+1,j//2,0] = z[ i-2+1,j ,0]
res[i//2+1,j//2,1] = (z[i+1,j,1] + z[i-2+1,j-2,1]) / 2
res[i//2+1,j//2,2] = z[ i+1,j-2 ,2]
res[i//2+1,j//2+1,0] = z[ i-2+1,j+1 ,0]
res[i//2+1,j//2+1,1] = (z[i+1,j+1,1] + z[i-2+1,j-2+1,1]) / 2
res[i//2+1,j//2+1,2] = z[ i+1,j-2+1 ,2]
res[i//2,j//2+1,0] = z[ i-2,j+1 ,0]
res[i//2,j//2+1,1] = (z[i,j+1,1] + z[i-2,j-2+1,1]) / 2
res[i//2,j//2+1,2] = z[ i,j-2+1 ,2]
return cv2.resize(res, (op.input_shape[0], op.input_shape[1]))
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 2023
# Authors: Mauro Dalla Mura and Matthieu Muller
"""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
from src.methods.charpentier_laurine.functions import superpixel
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.
"""
input_shape = (y.shape[0], y.shape[1], 3)
op = CFA(cfa, input_shape)
res = superpixel(op, y)
return res
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 2023
# Authors: Mauro Dalla Mura and Matthieu Muller
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment