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
a79dfea5
Commit
a79dfea5
authored
1 year ago
by
Tom Chardon
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
ea3dd9e2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/methods/Chardon_tom/reconstruct.py
+106
-0
106 additions, 0 deletions
src/methods/Chardon_tom/reconstruct.py
with
106 additions
and
0 deletions
src/methods/Chardon_tom/reconstruct.py
0 → 100644
+
106
−
0
View file @
a79dfea5
"""
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.chardon_tom.utils
import
*
import
pywt
#!!!!!!!! It is normal that the reconstructions lasts several minutes (3min on my computer)
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
)
res
=
op
.
adjoint
(
y
)
N
,
M
=
input_shape
[
0
],
input_shape
[
1
]
#interpolating green channel
for
i
in
range
(
N
):
for
j
in
range
(
M
):
if
res
[
i
,
j
,
1
]
==
0
:
neighbors
=
get_neighbors
(
res
,
1
,
i
,
j
,
N
,
M
)
weights
=
get_weights
(
res
,
i
,
j
,
1
,
N
,
M
)
res
[
i
,
j
,
1
]
=
interpolate_green
(
weights
,
neighbors
)
#first intepolation of red channel
for
i
in
range
(
1
,
N
,
2
):
for
j
in
range
(
0
,
M
,
2
):
neighbors
=
get_neighbors
(
res
,
0
,
i
,
j
,
N
,
M
)
neighbors_G
=
get_neighbors
(
res
,
1
,
i
,
j
,
N
,
M
)
weights
=
get_weights
(
res
,
i
,
j
,
0
,
N
,
M
)
res
[
i
,
j
,
0
]
=
interpolate_red_blue
(
weights
,
neighbors
,
neighbors_G
)
# second interpolation of red channel
for
i
in
range
(
N
):
for
j
in
range
(
M
):
if
res
[
i
,
j
,
0
]
==
0
:
neighbors
=
get_neighbors
(
res
,
0
,
i
,
j
,
N
,
M
)
weights
=
get_weights
(
res
,
i
,
j
,
0
,
N
,
M
)
res
[
i
,
j
,
0
]
=
interpolate_green
(
weights
,
neighbors
)
#first interpolation of blue channel
for
i
in
range
(
0
,
N
,
2
):
for
j
in
range
(
1
,
M
,
2
):
neighbors
=
get_neighbors
(
res
,
2
,
i
,
j
,
N
,
M
)
neighbors_G
=
get_neighbors
(
res
,
1
,
i
,
j
,
N
,
M
)
weights
=
get_weights
(
res
,
i
,
j
,
2
,
N
,
M
)
res
[
i
,
j
,
2
]
=
interpolate_red_blue
(
weights
,
neighbors
,
neighbors_G
)
#second interpolation of blue channel
for
i
in
range
(
N
):
for
j
in
range
(
M
):
if
res
[
i
,
j
,
2
]
==
0
:
neighbors
=
get_neighbors
(
res
,
2
,
i
,
j
,
N
,
M
)
weights
=
get_weights
(
res
,
i
,
j
,
2
,
N
,
M
)
res
[
i
,
j
,
2
]
=
interpolate_green
(
weights
,
neighbors
)
# k=0
# while k<2 :
# for i in range(input_shape[0]):
# for j in range(input_shape[1]):
# res[i][j][1] = correction_green(res,i,j,N,M)
# for i in range(input_shape[0]):
# for j in range(input_shape[1]):
# res[i][j][0] = correction_red(res,i,j,N,M)
# for i in range(input_shape[0]):
# for j in range(input_shape[1]):
# res[i][j][2] = correction_blue(res,i,j,N,M)
# k+=1
res
[
res
>
1
]
=
1
res
[
res
<
0
]
=
0
return
res
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