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
Matthieu Muller
sicom_image_analysis_project
Commits
bf050b09
Commit
bf050b09
authored
1 year ago
by
Theresa El Murr
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
92075723
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!32
EL-MURR
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/methods/EL-MURR-Theresa/malvar.py
+157
-0
157 additions, 0 deletions
src/methods/EL-MURR-Theresa/malvar.py
with
157 additions
and
0 deletions
src/methods/EL-MURR-Theresa/malvar.py
0 → 100644
+
157
−
0
View file @
bf050b09
import
numpy
as
np
from
scipy.signal
import
correlate2d
from
src.forward_model
import
CFA
def
malvar_he_cutler
(
y
:
np
.
ndarray
,
op
:
CFA
)
->
np
.
ndarray
:
"""
Performs demosaicing using the malvar-he-cutler algorithm
Args:
op (CFA): CFA operator.
y (np.ndarray): Mosaicked image.
Returns:
np.ndarray: Demosaicked image.
"""
red_mask
,
green_mask
,
blue_mask
=
[
op
.
mask
[:,
:,
0
],
op
.
mask
[:,
:,
1
],
op
.
mask
[:,
:,
2
]]
mosaicked_image
=
np
.
float32
(
y
)
demosaicked_image
=
np
.
empty
(
op
.
input_shape
)
if
op
.
cfa
==
'
quad_bayer
'
:
filters
=
get_quad_bayer_filters
()
else
:
filters
=
get_default_filters
()
demosaicked_image
=
apply_demosaicking_filters
(
mosaicked_image
,
demosaicked_image
,
red_mask
,
green_mask
,
blue_mask
,
filters
)
return
demosaicked_image
def
get_quad_bayer_filters
():
coefficient_scale
=
0.03125
return
{
"
G_at_R_and_B
"
:
np
.
array
([
[
0
,
0
,
0
,
0
,
-
1
,
-
1
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
-
1
,
-
1
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
2
,
2
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
2
,
2
,
0
,
0
,
0
,
0
],
[
-
1
,
-
1
,
2
,
2
,
4
,
4
,
2
,
2
,
-
1
,
-
1
],
[
-
1
,
-
1
,
2
,
2
,
4
,
4
,
2
,
2
,
-
1
,
-
1
],
[
0
,
0
,
0
,
0
,
2
,
2
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
2
,
2
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
-
1
,
-
1
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
-
1
,
-
1
,
0
,
0
,
0
,
0
]
])
*
coefficient_scale
,
"
R_at_GR_and_B_at_GB
"
:
np
.
array
([
[
0
,
0
,
0
,
0
,
0.5
,
0.5
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0.5
,
0.5
,
0
,
0
,
0
,
0
],
[
0
,
0
,
-
1
,
-
1
,
0
,
0
,
-
1
,
-
1
,
0
,
0
],
[
0
,
0
,
-
1
,
-
1
,
0
,
0
,
-
1
,
-
1
,
0
,
0
],
[
-
1
,
-
1
,
4
,
4
,
5
,
5
,
4
,
4
,
-
1
,
-
1
],
[
-
1
,
-
1
,
4
,
4
,
5
,
5
,
4
,
4
,
-
1
,
-
1
],
[
0
,
0
,
-
1
,
-
1
,
0
,
0
,
-
1
,
-
1
,
0
,
0
],
[
0
,
0
,
-
1
,
-
1
,
0
,
0
,
-
1
,
-
1
,
0
,
0
],
[
0
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,
2
,
2
,
0
,
0
],
[
0
,
0
,
0
,
0
,
-
1.5
,
-
1.5
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
-
1.5
,
-
1.5
,
0
,
0
,
0
,
0
]
])
*
coefficient_scale
,
}
def
get_default_filters
():
coefficient_scale
=
0.125
return
{
"
G_at_R_and_B
"
:
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
]
])
*
coefficient_scale
,
"
R_at_GR_and_B_at_GB
"
:
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
]
])
*
coefficient_scale
,
"
R_at_GB_and_B_at_GR
"
:
np
.
array
([
[
0
,
0
,
-
1
,
0
,
0
],
[
0
,
-
1
,
4
,
-
1
,
0
],
[
0.5
,
0
,
5
,
0
,
0.5
],
[
0
,
-
1
,
4
,
-
1
,
0
],
[
0
,
0
,
-
1
,
0
,
0
]
])
*
coefficient_scale
,
"
R_at_B_and_B_at_R
"
:
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
]
])
*
coefficient_scale
,
}
def
apply_demosaicking_filters
(
image
,
res
,
red_mask
,
green_mask
,
blue_mask
,
filters
):
red_channel
=
image
*
red_mask
green_channel
=
image
*
green_mask
blue_channel
=
image
*
blue_mask
# Create the green channel after applying a filter
green_channel
=
np
.
where
(
np
.
logical_or
(
red_mask
==
1
,
blue_mask
==
1
),
correlate2d
(
image
,
filters
[
'
G_at_R_and_B
'
],
mode
=
"
same
"
,
boundary
=
"
symm
"
),
green_channel
)
# Define masks for extracting pixel values
red_row_mask
=
np
.
any
(
red_mask
==
1
,
axis
=
1
)[:,
np
.
newaxis
].
astype
(
np
.
float32
)
red_col_mask
=
np
.
any
(
red_mask
==
1
,
axis
=
0
)[
np
.
newaxis
].
astype
(
np
.
float32
)
blue_row_mask
=
np
.
any
(
blue_mask
==
1
,
axis
=
1
)[:,
np
.
newaxis
].
astype
(
np
.
float32
)
blue_col_mask
=
np
.
any
(
blue_mask
==
1
,
axis
=
0
)[
np
.
newaxis
].
astype
(
np
.
float32
)
def
update_channel
(
channel
,
row_mask
,
col_mask
,
filter_key
):
return
np
.
where
(
np
.
logical_and
(
row_mask
==
1
,
col_mask
==
1
),
correlate2d
(
image
,
filters
[
filter_key
],
mode
=
"
same
"
,
boundary
=
"
symm
"
),
channel
)
# Update the red channel and blue channel
red_channel
=
update_channel
(
red_channel
,
red_row_mask
,
blue_col_mask
,
'
R_at_GR_and_B_at_GB
'
)
red_channel
=
update_channel
(
red_channel
,
blue_row_mask
,
red_col_mask
,
'
R_at_GB_and_B_at_GR
'
)
blue_channel
=
update_channel
(
blue_channel
,
blue_row_mask
,
red_col_mask
,
'
R_at_GR_and_B_at_GB
'
)
blue_channel
=
update_channel
(
blue_channel
,
red_row_mask
,
blue_col_mask
,
'
R_at_GB_and_B_at_GR
'
)
# Update R channel and B channel again
red_channel
=
update_channel
(
red_channel
,
blue_row_mask
,
blue_col_mask
,
'
R_at_B_and_B_at_R
'
)
blue_channel
=
update_channel
(
blue_channel
,
red_row_mask
,
red_col_mask
,
'
R_at_B_and_B_at_R
'
)
res
[:,
:,
0
]
=
red_channel
res
[:,
:,
1
]
=
green_channel
res
[:,
:,
2
]
=
blue_channel
return
res
\ No newline at end of file
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