Skip to content
Snippets Groups Projects
Commit fabf109c authored by mounael15's avatar mounael15
Browse files

last

parent 6f6fc640
No related branches found
No related tags found
1 merge request!6Master
...@@ -391,7 +391,7 @@ ...@@ -391,7 +391,7 @@
"kind": 2, "kind": 2,
"importPath": "src.methods.ELAMRANI_Mouna.functions", "importPath": "src.methods.ELAMRANI_Mouna.functions",
"description": "src.methods.ELAMRANI_Mouna.functions", "description": "src.methods.ELAMRANI_Mouna.functions",
"peekOfCode": "def find_Knearest_neighbors(z, chan, i, j, N, M):\n \"\"\"Finds all the neighbors of a pixel on a given channel\"\"\"\n return np.array([z[(i+di)%N, (j+dj)%M, chan] for di in range(-1, 2) for dj in range(-1, 2)])\ndef calculate_directional_gradients(neighbors):\n \"\"\"Calculates the directional derivative of a pixel\"\"\"\n P1, P2, P3, P4, P5, P6, P7, P8, P9 = neighbors\n Dx, Dy = (P4 - P6)/2, (P2 - P8)/2\n Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2))\n return [Dx, Dy, Dxd, Dyd]\ndef calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):", "peekOfCode": "def find_Knearest_neighbors(z, chan, i, j, N, M):\n \"\"\"Finds a pixel's neighbors on a channel\"\"\"\n return np.array([z[(i+di)%N, (j+dj)%M, chan] for di in range(-1, 2) for dj in range(-1, 2)])\ndef calculate_directional_gradients(neighbors):\n \"\"\"Gives the directional derivative\"\"\"\n P1, P2, P3, P4, P5, P6, P7, P8, P9 = neighbors\n Dx, Dy = (P4 - P6)/2, (P2 - P8)/2\n Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2))\n return [Dx, Dy, Dxd, Dyd]\ndef calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):",
"detail": "src.methods.ELAMRANI_Mouna.functions", "detail": "src.methods.ELAMRANI_Mouna.functions",
"documentation": {} "documentation": {}
}, },
...@@ -400,7 +400,7 @@ ...@@ -400,7 +400,7 @@
"kind": 2, "kind": 2,
"importPath": "src.methods.ELAMRANI_Mouna.functions", "importPath": "src.methods.ELAMRANI_Mouna.functions",
"description": "src.methods.ELAMRANI_Mouna.functions", "description": "src.methods.ELAMRANI_Mouna.functions",
"peekOfCode": "def calculate_directional_gradients(neighbors):\n \"\"\"Calculates the directional derivative of a pixel\"\"\"\n P1, P2, P3, P4, P5, P6, P7, P8, P9 = neighbors\n Dx, Dy = (P4 - P6)/2, (P2 - P8)/2\n Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2))\n return [Dx, Dy, Dxd, Dyd]\ndef calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):\n \"\"\"Finds all the neighbors of a pixel on a given channel\"\"\"\n [Dx,Dy,Dxd,Dyd] = dir_deriv\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh", "peekOfCode": "def calculate_directional_gradients(neighbors):\n \"\"\"Gives the directional derivative\"\"\"\n P1, P2, P3, P4, P5, P6, P7, P8, P9 = neighbors\n Dx, Dy = (P4 - P6)/2, (P2 - P8)/2\n Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2))\n return [Dx, Dy, Dxd, Dyd]\ndef calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):\n [Dx,Dy,Dxd,Dyd] = dir_deriv\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh\n E = []",
"detail": "src.methods.ELAMRANI_Mouna.functions", "detail": "src.methods.ELAMRANI_Mouna.functions",
"documentation": {} "documentation": {}
}, },
...@@ -409,7 +409,7 @@ ...@@ -409,7 +409,7 @@
"kind": 2, "kind": 2,
"importPath": "src.methods.ELAMRANI_Mouna.functions", "importPath": "src.methods.ELAMRANI_Mouna.functions",
"description": "src.methods.ELAMRANI_Mouna.functions", "description": "src.methods.ELAMRANI_Mouna.functions",
"peekOfCode": "def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):\n \"\"\"Finds all the neighbors of a pixel on a given channel\"\"\"\n [Dx,Dy,Dxd,Dyd] = dir_deriv\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh\n E = []\n c = 1\n for k in range (-1,2):\n for k in range (-1,2):\n n = find_Knearest_neighbors(z,chan,i+k,j+k,N,M)\n dd = calculate_directional_gradients(n)", "peekOfCode": "def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):\n [Dx,Dy,Dxd,Dyd] = dir_deriv\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh\n E = []\n c = 1\n for k in range (-1,2):\n for k in range (-1,2):\n n = find_Knearest_neighbors(z,chan,i+k,j+k,N,M)\n dd = calculate_directional_gradients(n)\n if c == 1 or c == 9:",
"detail": "src.methods.ELAMRANI_Mouna.functions", "detail": "src.methods.ELAMRANI_Mouna.functions",
"documentation": {} "documentation": {}
}, },
...@@ -418,7 +418,7 @@ ...@@ -418,7 +418,7 @@
"kind": 2, "kind": 2,
"importPath": "src.methods.ELAMRANI_Mouna.functions", "importPath": "src.methods.ELAMRANI_Mouna.functions",
"description": "src.methods.ELAMRANI_Mouna.functions", "description": "src.methods.ELAMRANI_Mouna.functions",
"peekOfCode": "def interpolate_pixel(neigh,weights):\n \"\"\"interpolates pixels from a grid where one of two pixels is missing regularly spaced\"\"\"\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh\n [E1,E2,E3,E4,E6,E7,E8,E9] = weights\n num5 = E2*P2 + E4*P4 + E6*P6 + E8*P8\n den5 = E2 + E4 + E6 + E8\n I5 = num5/den5\n return I5\ndef interpolate_RedBlue(neighbors, neighbors_G, weights):\n \"\"\"Interpolates the central missing pixel from the red or blue channel from a Bayer pattern.\"\"\"", "peekOfCode": "def interpolate_pixel(neigh,weights):\n \"\"\"This function performs interpolation for a single pixel by calculating a weighted average of its neighboring pixels\"\"\"\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh\n [E1,E2,E3,E4,E6,E7,E8,E9] = weights\n num5 = E2*P2 + E4*P4 + E6*P6 + E8*P8\n den5 = E2 + E4 + E6 + E8\n I5 = num5/den5\n return I5\ndef interpolate_RedBlue(neighbors, neighbors_G, weights):\n \"\"\"This function specifically interpolates a pixel in the red or blue channels\"\"\"",
"detail": "src.methods.ELAMRANI_Mouna.functions", "detail": "src.methods.ELAMRANI_Mouna.functions",
"documentation": {} "documentation": {}
}, },
...@@ -427,7 +427,7 @@ ...@@ -427,7 +427,7 @@
"kind": 2, "kind": 2,
"importPath": "src.methods.ELAMRANI_Mouna.functions", "importPath": "src.methods.ELAMRANI_Mouna.functions",
"description": "src.methods.ELAMRANI_Mouna.functions", "description": "src.methods.ELAMRANI_Mouna.functions",
"peekOfCode": "def interpolate_RedBlue(neighbors, neighbors_G, weights):\n \"\"\"Interpolates the central missing pixel from the red or blue channel from a Bayer pattern.\"\"\"\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neighbors\n [G1,G2,G3,G4,G5,G6,G7,G8,G9] = neighbors_G\n [E1,E2,E3,E4,E6,E7,E8,E9] = weights\n num5 = ((E1*P1)/G1) + ((E3*P3)/G3) + ((E7*P7)/G7) + ((E9*P9)/G9)\n den5 = E1 + E3 + E7 + E9\n I5 = G5 * num5/den5\n return I5", "peekOfCode": "def interpolate_RedBlue(neighbors, neighbors_G, weights):\n \"\"\"This function specifically interpolates a pixel in the red or blue channels\"\"\"\n [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neighbors\n [G1,G2,G3,G4,G5,G6,G7,G8,G9] = neighbors_G\n [E1,E2,E3,E4,E6,E7,E8,E9] = weights\n num5 = ((E1*P1)/G1) + ((E3*P3)/G3) + ((E7*P7)/G7) + ((E9*P9)/G9)\n den5 = E1 + E3 + E7 + E9\n I5 = G5 * num5/den5\n return I5",
"detail": "src.methods.ELAMRANI_Mouna.functions", "detail": "src.methods.ELAMRANI_Mouna.functions",
"documentation": {} "documentation": {}
}, },
...@@ -436,7 +436,7 @@ ...@@ -436,7 +436,7 @@
"kind": 2, "kind": 2,
"importPath": "src.methods.ELAMRANI_Mouna.reconstruct", "importPath": "src.methods.ELAMRANI_Mouna.reconstruct",
"description": "src.methods.ELAMRANI_Mouna.reconstruct", "description": "src.methods.ELAMRANI_Mouna.reconstruct",
"peekOfCode": "def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray:\n \"\"\"Performs demosaicking on y.\n Args:\n y (np.ndarray): Mosaicked image to be reconstructed.\n cfa (str): Name of the CFA. Can be bayer or quad_bayer.\n Returns:\n np.ndarray: Demosaicked image.\n \"\"\"\n # Define constants and operators\n cfa_name = 'bayer' # bayer or quad_bayer", "peekOfCode": "def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray:\n cfa_name = 'bayer' # bayer or quad_bayer\n input_shape = (y.shape[0], y.shape[1], 3)\n op = CFA(cfa_name, input_shape)\n img_res = op.adjoint(y)\n N = img_res[:,:,0].shape[0]\n M = img_res[:,:,0].shape[1]\n def interpolate_channel(img_res, channel, first_pass, N, M):\n for i in range(N):\n for j in range(M):",
"detail": "src.methods.ELAMRANI_Mouna.reconstruct", "detail": "src.methods.ELAMRANI_Mouna.reconstruct",
"documentation": {} "documentation": {}
}, },
......
import numpy as np import numpy as np
def find_Knearest_neighbors(z, chan, i, j, N, M): def find_Knearest_neighbors(z, chan, i, j, N, M):
"""Finds all the neighbors of a pixel on a given channel""" """Finds a pixel's neighbors on a channel"""
return np.array([z[(i+di)%N, (j+dj)%M, chan] for di in range(-1, 2) for dj in range(-1, 2)]) return np.array([z[(i+di)%N, (j+dj)%M, chan] for di in range(-1, 2) for dj in range(-1, 2)])
def calculate_directional_gradients(neighbors): def calculate_directional_gradients(neighbors):
"""Calculates the directional derivative of a pixel""" """Gives the directional derivative"""
P1, P2, P3, P4, P5, P6, P7, P8, P9 = neighbors P1, P2, P3, P4, P5, P6, P7, P8, P9 = neighbors
Dx, Dy = (P4 - P6)/2, (P2 - P8)/2 Dx, Dy = (P4 - P6)/2, (P2 - P8)/2
Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2)) Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2))
return [Dx, Dy, Dxd, Dyd] return [Dx, Dy, Dxd, Dyd]
def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M): def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):
"""Finds all the neighbors of a pixel on a given channel"""
[Dx,Dy,Dxd,Dyd] = dir_deriv [Dx,Dy,Dxd,Dyd] = dir_deriv
[P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh
E = [] E = []
...@@ -34,8 +34,7 @@ def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M): ...@@ -34,8 +34,7 @@ def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M):
return E return E
def interpolate_pixel(neigh,weights): def interpolate_pixel(neigh,weights):
"""This function performs interpolation for a single pixel by calculating a weighted average of its neighboring pixels"""
"""interpolates pixels from a grid where one of two pixels is missing regularly spaced"""
[P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh
[E1,E2,E3,E4,E6,E7,E8,E9] = weights [E1,E2,E3,E4,E6,E7,E8,E9] = weights
num5 = E2*P2 + E4*P4 + E6*P6 + E8*P8 num5 = E2*P2 + E4*P4 + E6*P6 + E8*P8
...@@ -44,7 +43,7 @@ def interpolate_pixel(neigh,weights): ...@@ -44,7 +43,7 @@ def interpolate_pixel(neigh,weights):
return I5 return I5
def interpolate_RedBlue(neighbors, neighbors_G, weights): def interpolate_RedBlue(neighbors, neighbors_G, weights):
"""Interpolates the central missing pixel from the red or blue channel from a Bayer pattern.""" """This function specifically interpolates a pixel in the red or blue channels"""
[P1,P2,P3,P4,P5,P6,P7,P8,P9] = neighbors [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neighbors
[G1,G2,G3,G4,G5,G6,G7,G8,G9] = neighbors_G [G1,G2,G3,G4,G5,G6,G7,G8,G9] = neighbors_G
[E1,E2,E3,E4,E6,E7,E8,E9] = weights [E1,E2,E3,E4,E6,E7,E8,E9] = weights
......
...@@ -4,17 +4,7 @@ from src.methods.ELAMRANI_Mouna.functions import * ...@@ -4,17 +4,7 @@ from src.methods.ELAMRANI_Mouna.functions import *
def run_reconstruction(y: np.ndarray, cfa: str) -> np.ndarray: 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.
"""
# Define constants and operators
cfa_name = 'bayer' # bayer or quad_bayer cfa_name = 'bayer' # bayer or quad_bayer
input_shape = (y.shape[0], y.shape[1], 3) input_shape = (y.shape[0], y.shape[1], 3)
op = CFA(cfa_name, input_shape) op = CFA(cfa_name, input_shape)
......
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