diff --git a/.vscode/PythonImportHelper-v2-Completion.json b/.vscode/PythonImportHelper-v2-Completion.json index 18adc695ef866459961a004c40b4130e1973502e..d97cbbb8e6ba64b2985094f491179e7f5768ac1f 100644 --- a/.vscode/PythonImportHelper-v2-Completion.json +++ b/.vscode/PythonImportHelper-v2-Completion.json @@ -391,7 +391,7 @@ "kind": 2, "importPath": "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", "documentation": {} }, @@ -400,7 +400,7 @@ "kind": 2, "importPath": "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", "documentation": {} }, @@ -409,7 +409,7 @@ "kind": 2, "importPath": "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", "documentation": {} }, @@ -418,7 +418,7 @@ "kind": 2, "importPath": "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", "documentation": {} }, @@ -427,7 +427,7 @@ "kind": 2, "importPath": "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", "documentation": {} }, @@ -436,7 +436,7 @@ "kind": 2, "importPath": "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", "documentation": {} }, diff --git a/src/methods/ELAMRANI_Mouna/functions.py b/src/methods/ELAMRANI_Mouna/functions.py index d7ad25de27a3f8f169382f0eb02f481d290b9c1d..7fc5028e238de3e2e6302cf293519a550b367bc9 100644 --- a/src/methods/ELAMRANI_Mouna/functions.py +++ b/src/methods/ELAMRANI_Mouna/functions.py @@ -1,18 +1,18 @@ import numpy as np 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)]) 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 Dx, Dy = (P4 - P6)/2, (P2 - P8)/2 Dxd, Dyd = (P3 - P7)/(2*np.sqrt(2)), (P1 - P9)/(2*np.sqrt(2)) return [Dx, Dy, Dxd, Dyd] 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 [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh E = [] @@ -34,8 +34,7 @@ def calculate_adaptive_weights(z, neigh, dir_deriv,chan,i,j,N,M): return E def interpolate_pixel(neigh,weights): - - """interpolates pixels from a grid where one of two pixels is missing regularly spaced""" + """This function performs interpolation for a single pixel by calculating a weighted average of its neighboring pixels""" [P1,P2,P3,P4,P5,P6,P7,P8,P9] = neigh [E1,E2,E3,E4,E6,E7,E8,E9] = weights num5 = E2*P2 + E4*P4 + E6*P6 + E8*P8 @@ -44,7 +43,7 @@ def interpolate_pixel(neigh,weights): return I5 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 [G1,G2,G3,G4,G5,G6,G7,G8,G9] = neighbors_G [E1,E2,E3,E4,E6,E7,E8,E9] = weights diff --git a/src/methods/ELAMRANI_Mouna/reconstruct.py b/src/methods/ELAMRANI_Mouna/reconstruct.py index 914020f974e2bd48ac6ac6b7647073858aafce3d..fed8c17a36bc2276913b81c3f4ac430bbbd21450 100644 --- a/src/methods/ELAMRANI_Mouna/reconstruct.py +++ b/src/methods/ELAMRANI_Mouna/reconstruct.py @@ -4,17 +4,7 @@ from src.methods.ELAMRANI_Mouna.functions import * 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 input_shape = (y.shape[0], y.shape[1], 3) op = CFA(cfa_name, input_shape)