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
ed4368ba
Commit
ed4368ba
authored
1 year ago
by
Patrick Dai
Browse files
Options
Downloads
Patches
Plain Diff
final commit
parent
25942cba
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/methods/dai/dai.pdf
+0
-0
0 additions, 0 deletions
src/methods/dai/dai.pdf
src/methods/dai/function.py
+65
-0
65 additions, 0 deletions
src/methods/dai/function.py
src/methods/dai/reconstruct.py
+58
-0
58 additions, 0 deletions
src/methods/dai/reconstruct.py
with
123 additions
and
0 deletions
src/methods/dai/dai.pdf
0 → 100644
+
0
−
0
View file @
ed4368ba
File added
This diff is collapsed.
Click to expand it.
src/methods/dai/function.py
0 → 100644
+
65
−
0
View file @
ed4368ba
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.
"""
res
=
np
.
empty
(
op
.
input_shape
)
z
=
op
.
adjoint
(
y
)
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
'
)
return
res
def
Spectral_difference
(
op
,
y
):
z
=
op
.
adjoint
(
y
)
y_hat
=
naive_interpolation
(
op
,
y
)
res
=
np
.
empty
(
op
.
input_shape
)
for
l
in
range
(
3
):
res
[:,:,
0
]
+=
z
[:,:,
l
]
+
convolve2d
(
z
[:,:,
0
]
-
y_hat
[:,:,
l
]
*
op
.
mask
[:,:,
0
],
ker_bayer_red_blue
,
mode
=
'
same
'
)
*
op
.
mask
[:,:,
l
]
res
[:,:,
1
]
+=
z
[:,:,
l
]
+
convolve2d
(
z
[:,:,
1
]
-
y_hat
[:,:,
l
]
*
op
.
mask
[:,:,
1
],
ker_bayer_green
,
mode
=
'
same
'
)
*
op
.
mask
[:,:,
l
]
res
[:,:,
2
]
+=
z
[:,:,
l
]
+
convolve2d
(
z
[:,:,
2
]
-
y_hat
[:,:,
l
]
*
op
.
mask
[:,:,
2
],
ker_bayer_red_blue
,
mode
=
'
same
'
)
*
op
.
mask
[:,:,
l
]
return
res
def
quad_bayer_to_bayer
(
y_quad
):
y_bayer
=
np
.
copy
(
y_quad
)
for
i
in
range
(
1
,
y_quad
.
shape
[
0
],
4
):
temp
=
np
.
copy
(
y_bayer
[
i
,:])
y_bayer
[
i
,:]
=
y_bayer
[
i
+
1
,:]
y_bayer
[
i
+
1
,:]
=
temp
for
j
in
range
(
1
,
y_quad
.
shape
[
1
],
4
):
temp
=
np
.
copy
(
y_bayer
[:,
j
])
y_bayer
[:,
j
]
=
y_bayer
[:,
j
+
1
]
y_bayer
[:,
j
+
1
]
=
temp
return
y_bayer
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
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/methods/dai/reconstruct.py
0 → 100644
+
58
−
0
View file @
ed4368ba
"""
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.dai.function
import
Spectral_difference
,
quad_bayer_to_bayer
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
)
if
op
.
cfa
==
'
bayer
'
:
res
=
Spectral_difference
(
op
,
y
)
else
:
op
.
mask
=
quad_bayer_to_bayer
(
op
.
mask
)
res
=
Spectral_difference
(
CFA
(
'
bayer
'
,
input_shape
),
quad_bayer_to_bayer
(
y
))
return
res
####a
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 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