Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sicom_image_analysis_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kourosh Gerayeli
sicom_image_analysis_project
Commits
5c7f74ce
Commit
5c7f74ce
authored
1 year ago
by
Matthieu Muller
Browse files
Options
Downloads
Patches
Plain Diff
Post merge changes
parent
0034b357
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/methods/baseline/demo_reconstruction.py
+153
-0
153 additions, 0 deletions
src/methods/baseline/demo_reconstruction.py
src/methods/baseline/reconstruct.py
+53
-0
53 additions, 0 deletions
src/methods/baseline/reconstruct.py
with
206 additions
and
0 deletions
src/methods/baseline/demo_reconstruction.py
0 → 100644
+
153
−
0
View file @
5c7f74ce
"""
A file containing a (pretty useless) reconstruction.
It serves as example of how the project works.
This file should NOT be modified.
"""
import
numpy
as
np
from
scipy.signal
import
convolve2d
from
src.forward_model
import
CFA
def
naive_interpolation
(
op
:
CFA
,
y
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Performs a simple interpolation of the lost pixels.
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
)
res
[:,
:,
0
]
=
convolve2d
(
z
[:,
:,
0
],
ker_bayer_red_blue
,
mode
=
'
same
'
)
res
[:,
:,
1
]
=
convolve2d
(
z
[:,
:,
1
],
ker_bayer_green
,
mode
=
'
same
'
)
res
[:,
:,
2
]
=
convolve2d
(
z
[:,
:,
2
],
ker_bayer_red_blue
,
mode
=
'
same
'
)
else
:
res
=
np
.
empty
(
op
.
input_shape
)
res
[:,
:,
0
]
=
varying_kernel_convolution
(
z
[:,
:,
0
],
K_list_red
)
res
[:,
:,
1
]
=
varying_kernel_convolution
(
z
[:,
:,
1
],
K_list_green
)
res
[:,
:,
2
]
=
varying_kernel_convolution
(
z
[:,
:,
2
],
K_list_blue
)
return
res
def
extract_padded
(
M
,
size
,
i
,
j
):
N_i
,
N_j
=
M
.
shape
res
=
np
.
zeros
((
size
,
size
))
middle_size
=
int
((
size
-
1
)
/
2
)
for
ii
in
range
(
-
middle_size
,
middle_size
+
1
):
for
jj
in
range
(
-
middle_size
,
middle_size
+
1
):
if
i
+
ii
>=
0
and
i
+
ii
<
N_i
and
j
+
jj
>=
0
and
j
+
jj
<
N_j
:
res
[
middle_size
+
ii
,
middle_size
+
jj
]
=
M
[
i
+
ii
,
j
+
jj
]
return
res
def
varying_kernel_convolution
(
M
,
K_list
):
N_i
,
N_j
=
M
.
shape
res
=
np
.
zeros_like
(
M
)
for
i
in
range
(
N_i
):
for
j
in
range
(
N_j
):
res
[
i
,
j
]
=
np
.
sum
(
extract_padded
(
M
,
K_list
[
4
*
(
i
%
4
)
+
j
%
4
].
shape
[
0
],
i
,
j
)
*
K_list
[
4
*
(
i
%
4
)
+
j
%
4
])
np
.
clip
(
res
,
0
,
1
,
res
)
return
res
K_identity
=
np
.
zeros
((
5
,
5
))
K_identity
[
2
,
2
]
=
1
K_red_0
=
np
.
zeros
((
5
,
5
))
K_red_0
[
2
,
:]
=
np
.
array
([
-
3
,
13
,
0
,
0
,
2
])
/
12
K_red_1
=
np
.
zeros
((
5
,
5
))
K_red_1
[
2
,
:]
=
np
.
array
([
2
,
0
,
0
,
13
,
-
3
])
/
12
K_red_8
=
np
.
zeros
((
5
,
5
))
K_red_8
[:
2
,
:
2
]
=
np
.
array
([[
-
1
,
-
1
],
[
-
1
,
9
]])
/
6
K_red_9
=
np
.
zeros
((
5
,
5
))
K_red_9
[:
2
,
3
:]
=
np
.
array
([[
-
1
,
-
1
],
[
9
,
-
1
]])
/
6
K_red_10
=
np
.
zeros
((
5
,
5
))
K_red_10
[:,
2
]
=
np
.
array
([
-
3
,
13
,
0
,
0
,
2
])
/
12
K_red_12
=
np
.
zeros
((
5
,
5
))
K_red_12
[
3
:,
:
2
]
=
np
.
array
([[
-
1
,
9
],
[
-
1
,
-
1
]])
/
6
K_red_13
=
np
.
zeros
((
5
,
5
))
K_red_13
[
3
:,
3
:]
=
np
.
array
([[
9
,
-
1
],
[
-
1
,
-
1
]])
/
6
K_red_14
=
np
.
zeros
((
5
,
5
))
K_red_14
[:,
2
]
=
np
.
array
([
2
,
0
,
0
,
13
,
-
3
])
/
12
K_list_red
=
[
K_red_0
,
K_red_1
,
K_identity
,
K_identity
,
K_red_0
,
K_red_1
,
K_identity
,
K_identity
,
K_red_8
,
K_red_9
,
K_red_10
,
K_red_10
,
K_red_12
,
K_red_13
,
K_red_14
,
K_red_14
]
K_green_2
=
np
.
zeros
((
5
,
5
))
K_green_2
[
2
,
:]
=
[
-
3
,
13
,
0
,
0
,
2
]
K_green_2
[:,
2
]
=
[
-
3
,
13
,
0
,
0
,
2
]
K_green_2
=
K_green_2
/
24
K_green_3
=
np
.
zeros
((
5
,
5
))
K_green_3
[
2
,
:]
=
[
2
,
0
,
0
,
13
,
-
3
]
K_green_3
[:,
2
]
=
[
-
3
,
13
,
0
,
0
,
2
]
K_green_3
=
K_green_3
/
24
K_green_6
=
np
.
zeros
((
5
,
5
))
K_green_6
[
2
,
:]
=
[
-
3
,
13
,
0
,
0
,
2
]
K_green_6
[:,
2
]
=
[
2
,
0
,
0
,
13
,
-
3
]
K_green_6
=
K_green_6
/
24
K_green_7
=
np
.
zeros
((
5
,
5
))
K_green_7
[
2
,
:]
=
[
2
,
0
,
0
,
13
,
-
3
]
K_green_7
[:,
2
]
=
[
2
,
0
,
0
,
13
,
-
3
]
K_green_7
=
K_green_7
/
24
K_list_green
=
[
K_identity
,
K_identity
,
K_green_2
,
K_green_3
,
K_identity
,
K_identity
,
K_green_6
,
K_green_7
,
K_green_2
,
K_green_3
,
K_identity
,
K_identity
,
K_green_6
,
K_green_7
,
K_identity
,
K_identity
]
K_list_blue
=
[
K_red_10
,
K_red_10
,
K_red_8
,
K_red_9
,
K_red_14
,
K_red_14
,
K_red_12
,
K_red_13
,
K_identity
,
K_identity
,
K_red_0
,
K_red_1
,
K_identity
,
K_identity
,
K_red_0
,
K_red_1
]
ker_bayer_red_blue
=
np
.
array
([[
1
,
2
,
1
],
[
2
,
4
,
2
],
[
1
,
2
,
1
]])
/
4
ker_bayer_green
=
np
.
array
([[
0
,
1
,
0
],
[
1
,
4
,
1
],
[
0
,
1
,
0
]])
/
4
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 2023
# Authors: Mauro Dalla Mura and Matthieu Muller
This diff is collapsed.
Click to expand it.
src/methods/baseline/reconstruct.py
0 → 100644
+
53
−
0
View file @
5c7f74ce
"""
The main file for the baseline reconstruction.
This file should NOT be modified.
"""
import
numpy
as
np
from
src.forward_model
import
CFA
from
src.methods.baseline.demo_reconstruction
import
naive_interpolation
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
=
naive_interpolation
(
op
,
y
)
return
res
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 2023
# Authors: Mauro Dalla Mura and Matthieu Muller
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment