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
62ce1f90
Commit
62ce1f90
authored
1 year ago
by
lahmare
Browse files
Options
Downloads
Patches
Plain Diff
Update
parent
7ce1560a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/methods/Elmehdi_lahmar/malvar.py
+66
-0
66 additions, 0 deletions
src/methods/Elmehdi_lahmar/malvar.py
src/methods/Elmehdi_lahmar/reconstruct.py
+58
-0
58 additions, 0 deletions
src/methods/Elmehdi_lahmar/reconstruct.py
with
124 additions
and
0 deletions
src/methods/Elmehdi_lahmar/malvar.py
0 → 100644
+
66
−
0
View file @
62ce1f90
import
numpy
as
np
from
scipy.signal
import
convolve2d
from
src.forward_model
import
CFA
def
malvar
(
y
:
np
.
ndarray
,
op
:
CFA
)
->
np
.
ndarray
:
"""
Malvar-He-Cutler demosaicing algorithm for Bayer pattern.
"""
# Convert the mosaicked image to the initial estimated channels.
z
=
op
.
adjoint
(
y
)
# Define convolution kernels
kernel_G_at_RB
=
np
.
array
([[
0
,
0
,
-
1
,
0
,
0
],
[
0
,
0
,
2
,
0
,
0
],
[
-
1
,
2
,
4
,
2
,
-
1
],
[
0
,
0
,
2
,
0
,
0
],
[
0
,
0
,
-
1
,
0
,
0
]])
/
8
kernel_RB_at_G
=
np
.
array
([[
0
,
0
,
0.5
,
0
,
0
],
[
0
,
-
1
,
0
,
-
1
,
0
],
[
-
1
,
4
,
5
,
4
,
-
1
],
[
0
,
-
1
,
0
,
-
1
,
0
],
[
0
,
0
,
0.5
,
0
,
0
]])
/
8
kernel_RB_at_RB
=
np
.
array
([[
0
,
0
,
-
1.5
,
0
,
0
],
[
0
,
2
,
0
,
2
,
0
],
[
-
1.5
,
0
,
6
,
0
,
-
1.5
],
[
0
,
2
,
0
,
2
,
0
],
[
0
,
0
,
-
1.5
,
0
,
0
]])
/
8
# Interpolate each channel
R
=
z
[:,
:,
0
]
G
=
z
[:,
:,
1
]
B
=
z
[:,
:,
2
]
mask
=
op
.
mask
R_m
,
G_m
,
B_m
=
mask
[:,
:,
0
],
mask
[:,
:,
1
],
mask
[:,
:,
2
]
# Interpolate G at R and B locations
G
=
np
.
where
(
np
.
logical_or
(
R_m
==
1
,
B_m
==
1
),
convolve2d
(
y
,
kernel_G_at_RB
,
mode
=
'
same
'
),
G
)
# Interpolate R at G and B locations, B at R and G locations
R
=
np
.
where
(
np
.
logical_or
(
G_m
==
1
,
B_m
==
1
),
convolve2d
(
y
,
kernel_RB_at_G
,
mode
=
'
same
'
),
R
)
B
=
np
.
where
(
np
.
logical_or
(
R_m
==
1
,
G_m
==
1
),
convolve2d
(
y
,
kernel_RB_at_G
,
mode
=
'
same
'
),
B
)
# Interpolate R at B locations and B at R locations
R
=
np
.
where
(
B_m
==
1
,
convolve2d
(
y
,
kernel_RB_at_RB
,
mode
=
'
same
'
),
R
)
B
=
np
.
where
(
R_m
==
1
,
convolve2d
(
y
,
kernel_RB_at_RB
,
mode
=
'
same
'
),
B
)
# Combine channels
return
np
.
clip
(
np
.
stack
((
R
,
G
,
B
),
axis
=-
1
),
0
,
1
)
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 2023
# Authors: Mauro Dalla Mura and Matthieu Muller
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/methods/Elmehdi_lahmar/reconstruct.py
0 → 100644
+
58
−
0
View file @
62ce1f90
"""
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.methods.Elmehdi_lahmar.malvar
import
malvar
from
src.forward_model
import
CFA
def
run_reconstruction
(
y
:
np
.
ndarray
,
cfa
:
str
)
->
np
.
ndarray
:
"""
Run the demosaicing process using Malvar-He-Cutler algorithm for Bayer pattern.
Args:
y (np.ndarray): The mosaicked image to be reconstructed.
cfa (str): Name of the CFA, expected to be
'
bayer
'
.
Returns:
np.ndarray: The demosaicked image.
"""
if
cfa
!=
'
bayer
'
:
raise
ValueError
(
"
Malvar-He-Cutler demosaicing only supports Bayer CFA pattern.
"
)
input_shape
=
(
y
.
shape
[
0
],
y
.
shape
[
1
],
3
)
op
=
CFA
(
cfa
,
input_shape
)
return
malvar
(
y
,
op
)
####
####
####
#### #### #### #############
#### ###### #### ##################
#### ######## #### ####################
#### ########## #### #### ########
#### ############ #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ######## #### #### ####
#### #### ## ###### #### #### ######
#### #### #### ## #### #### ############
#### #### ###### #### #### ##########
#### #### ########## #### #### ########
#### #### ######## #### ####
#### #### ############ ####
#### #### ########## ####
#### #### ######## ####
#### #### ###### ####
# 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