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
3732c684
Commit
3732c684
authored
1 year ago
by
Samia Bouddahab
Browse files
Options
Downloads
Patches
Plain Diff
Update src/methods/Samia_Bouddahab/function.py
parent
b07bdade
No related branches found
Branches containing commit
No related tags found
3 merge requests
!48
Update src/methods/Samia_Bouddahab/Project_Image_Analysis.pdf,...
,
!47
Bouddahs master patch 78178
,
!46
Update src/methods/Samia_Bouddahab/Project_Image_Analysis.pdf,...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/methods/Samia_Bouddahab/function.py
+94
-0
94 additions, 0 deletions
src/methods/Samia_Bouddahab/function.py
with
94 additions
and
0 deletions
src/methods/Samia_Bouddahab/function.py
0 → 100644
+
94
−
0
View file @
3732c684
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 12 07:38:51 2024
@author: etudiant
"""
import
numpy
as
np
from
scipy.signal
import
convolve2d
from
src.forward_model
import
CFA
from
scipy.ndimage
import
convolve
def
malvar_demosaicing
(
op
:
CFA
,
y
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Performs a malvar interpolation.
Args:
op (CFA): CFA operator.
y (np.ndarray): Mosaicked image.
Returns:
np.ndarray: Demosaicked image.
"""
z
=
op
.
adjoint
(
y
)
# Definnig Masks
R_m
=
op
.
mask
[:,
:,
0
]
G_m
=
op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# Red columns.
R_c
=
np
.
any
(
R_m
==
1
,
axis
=
0
)[
None
]
*
np
.
ones
(
R
.
shape
)
# Blue rows.
B_r
=
np
.
transpose
(
np
.
any
(
B_m
==
1
,
axis
=
1
)[
None
])
*
np
.
ones
(
B
.
shape
)
# Blue columns
B_c
=
np
.
any
(
B_m
==
1
,
axis
=
0
)[
None
]
*
np
.
ones
(
B
.
shape
)
del
R_m
,
B_m
R
=
np
.
where
(
np
.
logical_and
(
R_r
==
1
,
B_c
==
1
),
RBg_RBBR
,
R
)
R
=
np
.
where
(
np
.
logical_and
(
B_r
==
1
,
R_c
==
1
),
RBg_BRRB
,
R
)
B
=
np
.
where
(
np
.
logical_and
(
B_r
==
1
,
R_c
==
1
),
RBg_RBBR
,
B
)
B
=
np
.
where
(
np
.
logical_and
(
R_r
==
1
,
B_c
==
1
),
RBg_BRRB
,
B
)
R
=
np
.
where
(
np
.
logical_and
(
B_r
==
1
,
B_c
==
1
),
RBgr_BBRR
,
R
)
B
=
np
.
where
(
np
.
logical_and
(
R_r
==
1
,
R_c
==
1
),
RBgr_BBRR
,
B
)
del
RBg_RBBR
,
RBg_BRRB
,
RBgr_BBRR
,
R_r
,
R_c
,
B_r
,
B_c
# Combine channels
return
np
.
clip
(
np
.
stack
((
R
,
G
,
B
),
axis
=-
1
),
0
,
1
)
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